duanliang2017
2013-10-08 12:25PHP在循环中获取多个输入文本框的值
I used Javascript with PHP. In my HTML form it has a drop down(option) menu so that user can select the no. of authors. According to the number selected, dynamic input boxes will be displayed under names of authors. So here is my HTML form code.
<form method="post" action="" onsubmit="">
No. of Authors:<select id="steps_number" name="AuthorNo">
<option value="1" selected="selected" >1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select><br/>
Author Names:<div id="inputBoxes"></div><br/>
<button type="submit" name="submit"></form>
My javascript code to display dynamic input text boxes according to author number selected is;
<script language="javascript">
$(document).ready(function(){
$("#steps_number").change(function() {
var inputNum = $("#steps_number").val();
var inputCode = "";
for(i=0; i<inputNum; i++) {
inputCode += "<p class=\"inputBox\"><input name='inp' id=\"inputBox_" + i + "\" size=\"20\" type=\"text\"></p>"
}
$("#inputBoxes").html(inputCode);
});
});
</script>
PHP code to get values when submitted is;
<?php
if(isset($_POST['submit'])) {
$AuthorNo=strip_tags($_POST['AuthorNo']);
$AName=strip_tags($_POST['inp']);}
If the no of authors are selected as 2, two input text boxes will be displayed. If i submit it with two different values in each input box, only the value of 1st input box will be inserted to the database. Please tell me a way to name the input boxes in the loop differently and a way to call their values? Thank You.
- 点赞
- 回答
- 收藏
- 复制链接分享
1条回答
为你推荐
- 为数组中的每个项创建唯一ID,即使在页面上多次调用也是如此
- html
- php
- 2个回答
- 如何在while循环中从动态生成的文本框中发布多个条目
- mysql
- php
- 3个回答
- PHP在循环中获取多个输入文本框的值
- html
- javascript
- forms
- php
- 1个回答
- php文本框字数截取并翻页问题
- 1个回答