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 .....

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 .... ();

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 hope this will help you:

<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.

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:

<!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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.