| | |
Trying to put the value of a variable into a function parameter
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
Hello I have a JSON array data.cells that I need to iterate through to get the values out of and put the values into an onclick event listener.
Right now the variable name data.cells[i].letter is being based through the buildString function for each cell in my board, instead of the value of the variable. Same goes for the x and y variables.
Right now the variable name data.cells[i].letter is being based through the buildString function for each cell in my board, instead of the value of the variable. Same goes for the x and y variables.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
for(var i = 0; i < data.cells.length; i++) { var x = i % 4 + 1; var y = 0; if(i < 4) { y = 1; } else if(i < 8) { y = 2; } else if(i < 12) { y = 3; } else { y = 4; } document.getElementById('t' + i).addEventListener('click',function(data){ buildString(this, data.cells[i].letter, x, y);}, false); document.getElementById('t' + i).setTextValue(data.cells[i].letter); }
My Website <-- check out my site!
I have no idea what you're trying to do, you're already are passing those variables to the function.
javascript Syntax (Toggle Plain Text)
buildString(this, data.cells[i].letter, x, y);
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Feb 2007
Posts: 72
Reputation:
Solved Threads: 0
So when the buildString function gets called instead of some value for data.cells[i].letter like 'A' the string data.cells[i].letter is being passed to the function. I want to get what the value of data.cells[i].letter is.
My Website <-- check out my site!
This might get what you need. An example of passing the arguments ( or parameter ) to another function.
javascript Syntax (Toggle Plain Text)
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <meta http-equiv="Content-Script-Type" content="text/javascript" /> <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" /> <title>Getting Javascript Variable and Display into Table Cell</title> <style type="text/css"> /* <![CDATA[ */ html, body { background-color : #ccc; color : #405060; font : normal normal normal 95%/1.4 "Trebuchet MS", "Bernard MT Condensed", Tahoma, Verdana, Helvetica, Arial, sans-serif; min-height : 600px; text-align : center; height : auto; width : auto; } body .m-title { background-color : #444; border-top : 2px solid #000; border-bottom : 2px solid #000; color : #757575; margin-top : 0; padding : .100em 1em .100em 1em; text-align : left; width : auto; } div#main { background-color : #f0f0f0; margin : 0 auto; height : inherit !important; padding : 0; width : 100%; } div.tube { border : 1px solid; background-color : inherit; height : inherit !important; clear : both; padding : 1em; margin : 0; overflow : hidden; } table { border-top : 1px solid; border-collapse; margin : 1em auto 0 auto; padding : 0; text-align : left; width : 100%; } td { font : normal normal normal 10pt Verdana, Arial, sans-serif; border-bottom : 1px solid; letter-spacing : 2px; color : #696969; line-height : 1.5; white-space : pre-wrap; vertical-align : middle; padding : .300em 1em .300em 1em; } /* ]]> */ </style> <script type="text/javascript"> // <![CDATA[ var getArgs; var buildString; buildString = function( letter, cIndex, param3, param4 ) { // I was assuming that the buildString function is implemented this way. table = (( document.getElementById ) ? document.getElementById("data") : (( document.all ) ? document.all[ "data" ] : document.layers[ "data" ] )).rows[ 1 ].cells[ cIndex ]; text = "The letter <b>\u0022" + letter + "\u0022</b> is an argument ( or parameter ) passed by the getArgs() function gathered in first ROW at CELL " + (( cIndex ) + 1 ) + ".\n\n"; text += "Varible <b>x</b> = <span style=\"color : #f50\">" + param3 + "</span>\n"; text += "Varible <b>y</b> = <span style=\"color : #f50\">" + param4 + "</span>\n"; table.innerHTML = text; }; getArgs = function( rIndex ) { data = (( document.getElementById ) ? document.getElementById("data") : (( document.all ) ? document.all[ "data" ] : document.layers[ "data" ] )); cLen = data.rows[ rIndex ].cells.length for ( var i = 0; i < cLen; i++ ) { x = i % 4 + 1; y = 0; y = (( i < 4 ) ? 1 : (( i < 8 ) ? y = 2 : (( i < 12 ) ? y = 3 : y = 4 ))); buildString( data.rows[ rIndex ].cells[ i ].innerText, i, x, y ); } }; window.onload = function() { getArgs( 0 ) }; // ]]> </script> </head> <body> <div id="main"> <div id="content" class="tube"> <h2 class="m-title">Getting Javascript Variables</h2> <table id="data" frame="void" rules="none" summary="Getting Javascript Variables and passing it into Table Cell."> <tr> <td>A</td> <td>B</td> <td>C</td> </tr> <tr> <td>Not Set</td> <td>Not Set</td> <td>Not Set</td> </tr> </table> </div> </div> </body> </html>
![]() |
Similar Threads
- Recursive function with parameter - array of chars. (C++)
- template object as function parameter (C++)
- Problem Using a Function Parameter in a MySQL Statement (Python)
- passing function as a parameter to another function (C++)
- Wondering. (C++)
- Passing Variable Values as a parameter Name in MySQL (MySQL)
- help on passing variable to a function? (JavaScript / DHTML / AJAX)
- Deleting characters function ( with just one parameter) (C)
- just a quick question (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Javascript LOCATION constructor
- Next Thread: Multiple Submit Methods
| Thread Tools | Search this Thread |
acid2 ajax ajaxexample ajaxjspservlets array browser captcha captchaformproblem cart checkbox child class close codes date debugger decimal dependent disablefirebug dom editor element embed engine enter events explorer ext file firefox focus form forms frameworks getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl listbox maps marquee masterpage math matrixcaptcha media menu mp4 object onerror onmouseoutdivproblem onmouseover onreadystatechange parent paypal pdf php position post programming prototype rated redirect runtime safari scale scriptlets scroll search security session shopping size software star starrating stars synchronous toggle unicode variables web webservice wysiwyg \n






