我使用循环创建了一组文本框,它的名称是唯一的,并且名称是使用变量( like )指定的。那么,在循环中单击按钮后,如何检索该文本框中的值。真的,我不能离开这里。有人能帮帮我吗?下面给出了我的部分代码
$q1="select * from result where s_id=$sid";
$res1=mysql_query($q1,$link) or die($q1);
echo '<form action="editresultprofile.php?sid=$sid">';
while($row1=mysql_fetch_assoc($res1))
{
echo '<td><input type="text" name='.$row1['sub_name'].' class="textfield" value='.$row1['result'].'></td>';
}
echo '<input type="submit" value="update" ></form>';发布于 2012-03-18 13:44:14
通过PHP是不可能的。您必须使用javascript来实时获取文本框中的值。
但是使用php,你必须先提交表单,然后只有你才能获得页面上的数据,然后提交数据。例如,根据您的问题,只有editresultprofile.php能够获取数据值。
在editresultprofile.php上,您可以这样做
$name = $_POST['thesubname']; //You have to change the name to what is reflected on your case但是,如果您使用javascript,则可以在提交表单之前获得键入的值。
function getValues(){
var tbox = document.getElementById('yourtextboxid');
alert(tbox.value);
return false; //stop the submisison
}在窗体的onSubmit事件中附加函数。
<form onsubmit="return getValues()" >https://stackoverflow.com/questions/9756300
复制相似问题