i am trying to create dynamic textboxes. The textbox should be created only if the previous textbox is non-empty. So far i have done this
<!DOCTYPE html> <html> <head> <script> var i=0; function myFunction() { var box = document.createElement("input"); box.type = "text"; var str=box+i; if(i==0) { document.body.appendChild(box); } else if(document.getElementById('str').value!=0) { document.body.appendChild(box); } i++; } </script> </head> <body> <input type="button" id="button" onclick="myFunction()" value="Show box" /> </body> </html> but str is not recognised as element id. Any help will be appreciated.
strand you're not assigning IDs to any elements you create. Also, both branches of your if statement are doing the same thing.