Php 如何使用while循环在onchange中获取多个值
我想在while循环中使用onchange从选择框中获取值。但我只得到第一个价值。如何从所有数据中获取值Php 如何使用while循环在onchange中获取多个值,php,ajax,Php,Ajax,我想在while循环中使用onchange从选择框中获取值。但我只得到第一个价值。如何从所有数据中获取值 <tr> <td> <?php $i = 1; while ($i <= 10) { ?> <form> <se
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
我只是在php中使用while循环来实现这一点
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
有人能说出解决办法吗
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
提前谢谢
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
这是我的代码:
这是我的代码
<script type="text/javascript">
function showUser1()
{
var str = document.getElementById("process").value;
var str1 = document.getElementById("snp").value;
alert(str);
alert(str1);
if (str=="")
{
document.getElementById("txtHint1").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint1").innerHTML=xmlhttp.responseText;
}
}
//xmlhttp.open("GET","process.php?q="+str,true);
xmlhttp.open("GET","process.php?q=" + str + "&q1=" + str1, true);
xmlhttp.send();
}
</script>
<table cellpadding="1" cellspacing="1" border="0">
<tr>
<td id="txtHint">
<table cellpadding="1" cellspacing="1" border="0">
<tr>
<th style="padding-left:500px;">Serial Number</th>
<th> Status</th></tr>
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
echo $i++; /* the printed value would be $i before the increment (post-increment) */
?>
<form>
<select name="process" id="process" onchange="showUser1(this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select>
<input type="text" name="snp" id="snp" value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php } ?>
</td>
<td id="txtHint1"></td>
</tr>
</table>
</td>
</tr>
</table>
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
函数showUser1()
{
var str=document.getElementById(“进程”).value;
var str1=document.getElementById(“snp”).value;
警报(str);
警报(str1);
如果(str==“”)
{
document.getElementById(“txtHint1”).innerHTML=“”;
返回;
}
if(window.XMLHttpRequest)
{//IE7+、Firefox、Chrome、Opera、Safari的代码
xmlhttp=新的XMLHttpRequest();
}
其他的
{//IE6、IE5的代码
xmlhttp=新的ActiveXObject(“Microsoft.xmlhttp”);
}
xmlhttp.onreadystatechange=函数()
{
if(xmlhttp.readyState==4&&xmlhttp.status==200)
{
document.getElementById(“txtHint1”).innerHTML=xmlhttp.responseText;
}
}
//open(“GET”、“process.php?q=“+str,true”);
open(“GET”、“process.php?q=“+str+”&q1=“+str1,true”);
xmlhttp.send();
}
序列号
地位
挑选
尚未开始
关于进程。。。
在料场上
派遣
首先,我注意到您的代码中几乎没有错误
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
不要在while循环中包含表单
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
选择框名称和id应该是动态的[如process1、process2..]
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
在函数showUser1()中,必须传递两个参数
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
onchange=“javascript:return showUser1([loop counter],this.value);”
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
Javascript函数如下所示
函数showUser1(cnt、processValue){
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
“输入类型”文本框值应为“选择框”中的动态值
函数showUser1(i,processValue){
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
var str=processValue;var str1=document.getElementById(“snp”+
i) .价值
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
警报(str);警报(str1)
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
if(str==“”){document.getElementById(“txtHint1”).innerHTML=
“”;return;}如果(window.XMLHttpRequest){//IE7+的代码,
Firefox、Chrome、Opera、Safari xmlhttp=new XMLHttpRequest();}
else{//IE6、IE5 xmlhttp的代码=new
ActiveXObject(“Microsoft.XMLHTTP”);}XMLHTTP.onreadystatechange=
函数(){if(xmlhttp.readyState==4&&xmlhttp.status==200){
document.getElementById(“txtHint1”).innerHTML=
xmlhttp.responseText;}}//
xmlhttp.open(“GET”、“process.php?q=“+str,true”);xmlhttp.open(“GET”,
“process.php?q=“+str+”&q1=“+str1,true);xmlhttp.send()
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
}
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
序列号
地位
<tr>
<td>
<?php $i = 1;
while ($i <= 10) {
?>
<form>
<select name="process<?php echo $i;?>"
id="process<?php echo $i;?>"
onchange="showUser1(<?php echo $i;?>,this.value)">
<option value="" selected="selected">Select</option>
<option value="0">Not Yet Start</option>
<option value="1">On Process...</option>
<option value="2">On Stock Yard</option>
<option value="3">Despatched</option>
</select> <input type="text" name="snp<?php echo $i;?>"
id="snp<?php echo $i;?>"
value="<?php //echo $fetch['serial_number']; ?>" />
</form>
<?php $i++; /* the printed value would be $i before the increment (post-increment) */ } ?> </td>
<td id="txtHint1"></td>
</tr>
</table> </td> </tr> </table>
任何人都可以告诉我这个问题的解决方案…动态意味着,我不明白…我如何保持选择框和文本框的动态值…非常感谢你的回答。但是它不起作用。即使我在javascript的第一行中添加了警报,但它不起作用…让我知道问题是什么?哦,天哪…我也得到了文本框的值。…但是我没有从process.php得到任何东西。。。