使用 PHP 代码显示和隐藏文本框


showing and hiding text box using php code

我正在尝试弄清楚如何使用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>

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

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