1

我试图弄清楚如何使用 php 编码隐藏文本框。我正在使用一个包含 3 个单选按钮和 3 个文本框的表单。加载页面时,我只希望显示 3 个单选按钮和前 2 个文本框,并隐藏最后一个文本框。当用户单击更新单选按钮时,第二个文本框被隐藏,第三个文本框可见。我将如何使用此代码完成此操作?

使用此代码,我可以隐藏我的文本框。但是有没有办法隐藏与被隐藏的文本框相关的文本?

<html>
<head><title></title>
<script type="text/javascript">

function show()
{
if (document.getElementById('ins').checked){

document.getElementById("zn").style.display = "block";
document.getElementById("gpa").style.display = "block";
document.getElementById("ngpa").style.display = "none";
}
}
</script>

</head>
<body>
<form action = "index.php" method = 'post'>
<input type="radio" name="group" id = "ins" onclick="show()" /> Insert Student <br />
<input type="radio" name="group" id = "upd" /> Update Student <br />
<input type="radio" name="group" id = "del" /> Delete Student <br />
Enter Z-number: <input type='text' name = 'z' maxlength='9' />
<br />Enter GPA: <input type='text' name='gpa' />
<br /> Enter new GPA: <input type="text" name ="ngpa" value ="false" />
<br /><input type='submit' value='Submit request' name='submit' />
</form>
<?php
 if (isset($_POST['z'])) {
 $con = mysql_connect('localhost', 'jtinio', 'jtin666');
 if ($con) {
  mysql_select_db('jtinio', $con);

 $sql = "INSERT INTO Students VALUES (' ".$_POST['z']." ' , " .$_POST['gpa'].")";

 if (mysql_query($sql, $con)) echo 'Operation succeeded';
 else echo 'Not succeeded ' .mysql_error();




if (isset($_POST['ins'])) {
$sql = "SELECT * FROM Students";
$res = mysql_query($sql, $con);

echo "<table border ='1'>";
echo "<tr><th>Znum</th><th>GPA</th></tr>";
while ($r = mysql_fetch_array($res)) {
 echo "<tr><td>".$r['Znum']."</td></td>".$r['gpa']."</td></tr>";
}
echo "</table>";
}
mysql_close($con);
}
else {
echo 'Insertion failed'. 'Could not connect to DB.';}

}

?>
</body>
</html>
4

1 回答 1

3

PHP 是基于服务器的。您想要做的事情适用于用户交互(在浏览器中),因此 PHP 不是用于此目的的。

简而言之:使用 JavaScript(或 jQuery)

于 2012-04-28T13:29:08.947 回答