poofacer Posted May 8, 2007 Share Posted May 8, 2007 var options = new Array ("option1","option2", "option3","option4","option5", "option6","option7","option8","option9","option10"); for(var i=0; i<10; i++) { if(form.[b]options[i][/b].value == "") { ecount++; } } The above code is javascript. I have 10 input types with the names option1 to option10 which i generated using a for loop with PHP. My problem is that this part of my code is not working the way it should and the problem is the bold part. I want the for loop to generate those strings in the array in place of "options[i ]". but it doesnt seem to be proper syntax. i am new to js but have done C programming. If i test form.option1.value= "" it works perfectly. But i dont want to do that for all ten options and i am curious about why this doesnt work. Quote Link to comment Share on other sites More sharing options...
nogray Posted May 9, 2007 Share Posted May 9, 2007 if you have ids in your input <input type="text" name="option1" id="option1" ..... You can use the document.getElementById() ... if(document.getElementById(options[i]).value == "") .... If not, use the eval() function ... if (eval("form."+options[i]+".value") == "") .... Quote Link to comment Share on other sites More sharing options...
poofacer Posted May 9, 2007 Author Share Posted May 9, 2007 ooo thank you so much. yes it works now! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.