Help connecting javascript text boxes to html form code for submitting
Javascript is not my thing. I will leave it at that. I am attempting to learn, but I'm much better at php and html. So, I've some Javascript to do what I need (add a text box when a button is pressed) but I have no idea how to connect the boxes created to variables that can then be transferred to my php processing form via post. any help would be great. here is the code so far.
<div id = "textfield1"></div>
<div id = "textfield2"></div>
<div id = "textfield3"></div>
<div id = "textfield4"></div>
<div id = "textfield5"></div>
<div id = "textfield6"></div>
<div id = "textfield7"></div>
<div id = "textfield8"></div>
<div id = "textfield9"></div>
<div id = "textfield10"></div>
<div id = "textfield11"></div>
<div id = "textfield12"></div>
<div id = "textfield13"></div>
<div id = "textfield14"></div>
<div id = "textfield15"></div>
<input type = "button" value = "Add Textbox" onclick = "addbox()">
<script type = "text/javascript">
var i = 1;
function addbox() {
if (i <= 15) { // max number of textboxes
document.getElementById('textfield'+[i]).innerHTML = "<input type='text' si开发者_如何学JAVAze = '20' />";
i++;
}
else {
alert ("No more textboxes possible")
}
}
</script>
You need to give your inputs name attributes...
if (i <= 15) { // max number of textboxes
document.getElementById('textfield'+[i]).innerHTML = "<input type='text' name='myInput" + i + "' size = '20' />";
i++;
}
Quite simply you need to assign a name attribute to the input element you are creating. The form will automatically bundle this with its post data to the server when submitted.
精彩评论