beginnerprogrammer
beginnerprogrammer

Reputation: 183

showing and hiding text box using php code

I'm trying to figure out how to hide a text box using php coding. I am using a form, which contains 3 radio buttons, and 3 text boxes as well. when the page is loaded, i only want the 3 radio buttons and the first 2 text boxes to appear, and the last text box to be hidden. when the user clicks the update radio button, the 2nd text box is hidden and the 3rd text box is visible. how would i accomplish this with this code?

with this code i am able to hide my text boxes. but is there a way to hide the text as well that is associated with the textbox that is being hidden?

<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>

Upvotes: 1

Views: 5928

Answers (1)

Dr.Kameleon
Dr.Kameleon

Reputation: 22820

PHP is server-based. What you want to do applies to user interaction (in the browser), so PHP is not the one to use for this purpose.

In a few words : use JavaScript (or jQuery)

Upvotes: 3

Related Questions