php - Dealing with an array of input text dynamically generated in JavaScript -
i want phone numbers of customer in form generates input text dynamically. have made this
<html> <head> <title> telephones </title> <script language="javascript"> function add(type) { //create input text dynamically. if(typeof add.counter=='undefined') { add.counter=0; } add.counter++; var element = document.createelement("input"); //assign different attributes element. element.setattribute("type", type); element.setattribute("value", ""); element.setattribute("name", type.concat(add.counter)); var foo = document.getelementbyid("foobar"); //append element in page (in span). foo.appendchild(element); return add.counter; } </script> </head> <body> <form action="test1.php" method="post"> //here think there problem <input type="button" value="add" onclick="<?php echo "add('text')";?>"/> <input type="submit" value="add" /> <span id="foobar"> </span> </form> </body> </html>
i want array of names of input text, or last value of counter
if set input name "whatever[]" php automatically create array input data need here change
element.setattribute("name", type.concat(add.counter)); // element.setattribute("name", "thename[]");
and don't want reuse type of elements it's name - that's 2 different things, come better
and drop counter stuff
Comments
Post a Comment