while loop is not working in javascript code?

TehAdam

New Member
In this code I'm trying to generate dynamic text fields based on the input of select field which handled by addInput(divname) function using on change event but the while loop inside addInput function is not working and when i remove while loop its working. i have to generate selected no. of text fields... and also the text fields should change when i select different number...\[code\]<!DOCTYPE html><html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> </head> <body> <form action="adduniv.php" method="post"> University Name: <input type="text" name="college"> No. of branches: <div id="dynamicInput"> <select name="branches" id="branches" onchange="if (this.selectedIndex) addInput('dynamicInput');;" "> <option value="http://stackoverflow.com/questions/15904068/1">1</option> <option value="http://stackoverflow.com/questions/15904068/2">2</option> <option value="http://stackoverflow.com/questions/15904068/3">3</option> <option value="http://stackoverflow.com/questions/15904068/4">4</option> <option value="http://stackoverflow.com/questions/15904068/5">5</option> <option value="http://stackoverflow.com/questions/15904068/6">6</option> <option value="http://stackoverflow.com/questions/15904068/7">7</option> <option value="http://stackoverflow.com/questions/15904068/8">8</option> </select> </div> <script> var counter = 0; var limit = 3; function addInput(divName) { var k=parseInt(document.getElementById("branches")); var newdiv; while(k>0) { newdiv = document.createElement('div'); newdiv.innerHTML = "Entry " + (counter + 1) + " <br><input type='text' name='myInputs[]'>"; document.getElementById(divName).appendChild(newdiv); counter++; k--; } } </script> <input type="submit" value="http://stackoverflow.com/questions/15904068/submit" /> </form> </body></html>\[/code\]
 
Top