| | |
how to append a function name with a foor loop index ??
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2008
Posts: 33
Reputation:
Solved Threads: 0
Hi all,
i ve a function which is responsible for some validations, disabling and enabling of some text boxes and a group of radio buttons ....
now i want to generate the function name to be called from another function using a for loop and then appending the for loop index to the function in question ....
something like this .....
here i want to append the index i to the makeChoice_ang() function ....
tried many ways .... but no go ...
i tried using this .... ['makeChoice_ang'+i]();
but this is making it an string ....
Please help me out or atleast point me in the right direction ....
Thanks a million in advance !!
i ve a function which is responsible for some validations, disabling and enabling of some text boxes and a group of radio buttons ....
now i want to generate the function name to be called from another function using a for loop and then appending the for loop index to the function in question ....
something like this .....
JavaScript Syntax (Toggle Plain Text)
function unCheckRadio(num) { var cont = num; var form = document.angular; for (var i = 0; i < cont; i++) { for(var j = 0; j < form['lim_set'+i].length; j++ ) { form['lim_set'+i][j].checked = form['lim_set'+i][j].defaultChecked; } makeChoice_ang(); } }
here i want to append the index i to the makeChoice_ang() function ....
tried many ways .... but no go ...
i tried using this .... ['makeChoice_ang'+i]();
but this is making it an string ....
Please help me out or atleast point me in the right direction ....
Thanks a million in advance !!
Last edited by peter_budo; Aug 4th, 2009 at 6:21 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
I hope this will help you:
But this is not a good practise.
html Syntax (Toggle Plain Text)
<html> <script> function callAll() { for(var i = 0; i < 3; i++) { window['myFunction' + i](i); } } function myFunction0(i) { alert(i); } function myFunction1(i) { alert(i); } function myFunction2(i) { alert(i); } </script> <body onload='callAll()'> </body> </html>
But this is not a good practise.
When you think you have done a lot, then be ready for YOUR downfall.
Hi,
or you might also want to try this simulated document.
In this demo i will verify all the checkboxes set to have defaulted checked values:
hope we both helped...
-essential
or you might also want to try this simulated document.
In this demo i will verify all the checkboxes set to have defaulted checked values:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<title>http://www.daniweb.com</title>
<style type="text/css">
<!--
label { color : #555; font : norm 80%/2 Verdana; letter-spacing : 2px; }
-->
</style>
<script type="text/javascript">
<!--
var unCheckRadio = ( function( num ) {
var num = num || 0;
var isChecked = { }; // You may also use array in replaced for this object.
var form;
var chb;
(( form = document.angular ) ? form : document.getElementById( "angular" ));
for ( i = 0; i < num; i++ ) {
chb = form[ String( "lim_set" + i ) ];
chb.checked = chb.defaultChecked;
if ( chb.defaultChecked ) {
isChecked[ i ] = chb.id;
/*
* Simulating your makeChoice_ang() function,
and referencing the index
position of the i variable
via the isChecked = { } object. */
var makeChoice_ang = ( function( index ) {
var div;
(( div = document.getElementById( "output" )) ? div : div = document.all.output );
div.innerHTML = "";
div.innerHTML += "<br><br>This are the following checkboxes the has ( checked by default ) on the page:<br><hr>";
for ( checkedItem in index ) {
document.angular[ index[ checkedItem ]].style.border = "2px solid #F00";
/* This will highlight the ( checked by default ) checkboxes in your page. */
div.innerHTML += "<span style=\"color : #365d95; letter-spacing : 2px;\"><b>checkbox #" + (( checkedItem * 1 ) + 1 ) + "</b> — capturing i-index @:<br> position = <b>" + (( checkedItem * 1 ) + 1 ) + "</b></span><br><hr>";
} delete checkedItem;
return;
} )( isChecked );
}
} delete i;
return false;
} );
// -->
</script>
</head>
<body>
<div>
<form id="angular" name="angular" action="#" method="post" onsubmit="return unCheckRadio( 4 );">
<div>
<div style="margin-bottom : 1em;"><label for="lim_set0">[ CHECKBox #1 ] [ <input type="checkbox" id="lim_set0" name="lim_set0" value="0" checked> ]</label><br><br>
<label for="lim_set1">[ CHECKBox #2 ] [ <input type="checkbox" id="lim_set1" name="lim_set1" value="0"> ]</label><br><br>
<label for="lim_set2">[ CHECKBox #3 ] [ <input type="checkbox" id="lim_set2" name="lim_set2" value="0" checked> ]</label><br><br>
<label for="lim_set3">[ CHECKBox #4 ] [ <input type="checkbox" id="lim_set3" name="lim_set3" value="0"> ]</label><br>
</div>
<input type="submit" value="- test function -">
</div>
</form>
<div id="output"></div>
</div>
</body>
</html>hope we both helped...
-essential
Last edited by essential; Aug 3rd, 2009 at 4:17 am.
![]() |
Similar Threads
- Starting Python (Python)
- I need help with Program (Java)
- blackjack code (Python)
- How do I loop through a collection? (VB.NET)
- while loop and getline (C++)
- question about rand() function (C++)
- Help with Class, stuck. (C++)
- Need direction on how start this program (C++)
- Need direction on how start this programm (C++)
- How do I create a program using an Array ? (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: generating a table structure using JQuery
- Next Thread: Need help, is JavaScript the right language for making a firefox extension?
| Thread Tools | Search this Thread |
acid2 ajax ajaxcode ajaxexample ajaxhelp animate array automatically beta box bug calendar cart checkbox class codes column cookies createrange() css cursor date debugger decimal design dom download dropdown editor element embed enter error explorer firefox focus frameworks getselection google gwt hint html htmlform ie7 iframe images index internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jsp jump listbox maps masterpage math menu microsoft mimic mp4 object onmouseover parent paypal php player position post problem programming progressbar prototype redirect regex runtime safari scale scriptlets search select session shopping size sql text textarea toggle variables w3c website window windowofwords windowsxp wysiwyg \n





