Jump to content

how to disable a radio button


Adam77

Recommended Posts

hey guys please help me out here !

i did a time line which people fill their place in line with radio button , now i want to make the radio that

already been picked to be disable for everyone else so it cant be picked twice . i have an sql database where i put(by php) the submitted picking.

will appreciate any help !!!

Adam

Link to comment
Share on other sites

<form action="demo_form.asp">  Choice 1: <input type="radio" name="choice" value="ch1"><br>  Choice 2: <input type="radio" name="choice" value="ch2"><br>  Choice 3: <input type="radio" name="choice" value="ch3" disabled><br>  Choice 4: <input type="radio" name="choice" value="ch4"><br>  <input type="submit" value="Submit"></form>
Link to comment
Share on other sites

The user would submit the form. The next time you generate the form you would generate it with that radio button disabled. Perhaps also adding the name of the person who has that position.

<?php$ch[1] = '';$ch[2] = '';$ch[3] = 'disabled';$ch[4] = '';$assignname[1] = '';$assignname[2] = '';$assignname[3] = 'bobsmith';$assignname[4] = '';echo '<form action="process_form.php">';echo 'Choice 1: <input type="radio" name="choice" value="ch1"'.$ch[1].' >'.$assignname[1].'<br>';echo 'Choice 2: <input type="radio" name="choice" value="ch2"'.$ch[2].' >'.$assignname[2].'<br>';echo 'Choice 3: <input type="radio" name="choice" value="ch3"'.$ch[3].' >'.$assignname[3].'<br>';echo 'Choice 4: <input type="radio" name="choice" value="ch4"'.$ch[4].' >'.$assignname[4].'<br>';echo '<input type="submit" value="Submit">';echo '</form>';?>
Edited by davej
Link to comment
Share on other sites

it doesnt really help read all different function and i do have some clue in php .. i know i need to regenerate my radio buttons each time someone is picking a radio button but i dont

know how

 

this is all my php file

 

<?php
ini_set('display_errors', 'Off');
if(isset($_POST['submitted'])){
include("connect.php");
$choice = $_POST['placeInLine'];
mysql_query("INSERT INTO $table(choice) VALUES ($choice)") or die(mysql_error());
$sqlinsert = "INSERT INTO placeinline (choice) VALUES ($choice)";
$newrecord = "1 choice added to the line";
echo $newrecord;
$disabled = ($choice != '') ? 'disabled' : '';
} //end of the main if statment
?>
<!DOCTYPE html>
<html >
<head>
<title> shop </title>
<meta http-equiv="content-type" content="text/html; charset-utf-8" />
</head>
<body>
<form id= "line" name="line " action="index.php" method="post">
<input type="hidden" name="submitted" value="true"/>
<ul>
<li><input type="radio" name="placeInLine" id="choice1" value="1"'.$ch[1].' onclick="toggle('show')" />10:00-11:15</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice2" value="2"'.$ch[2].'onclick="toggle('show')" />10:15-10:30</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice3" value="3"'.$ch[3].' onclick="toggle('show')"/>10:30-11:45</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice4" value="4"'.$ch[4].' onclick="toggle('show')"/>10:45-11:15</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice5" value="5" onclick="toggle('show')"/>11:15-11:30</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice6" value="6" onclick="toggle('show')"/>11:30-11:45</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice7" value="7" onclick="toggle('show')"/>11:45-12:00</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<li><input type="radio" name="placeInLine" id="choice8" value="8" onclick="toggle('show')"/>12:00-12:15</li>
<div><form action="" method="POST"></form><input type="radio" name="gender" id="man">man
<form action="" method="POST"></form><input type="radio" name="gender" id="woman">woman
<form action="" method="POST"></form>remarks<input type="<textarea name="Name" rows="8" cols="40"></textarea></div>
<br />
<input type="submit" value="Save my choice" class="button" />
</ul>
</form>
<script type="text/javascript" src="jquery-1.11.0.js"></script>
<script type="text/javascript" src="javaScript.js"></script>
</body>
</html>
Link to comment
Share on other sites

hey guys i simplify my code but i still have a little syntax problem i cant solve, please help

 

<?php
include("connect.php");
ini_set('display_errors', 'Off');
if(isset($_POST['submitted'])){
$choice = $_POST['placeInLine'];
$query = "SELECT `choice` FROM `placeinline`";
$result = mysql_query($query );
if($query_run = mysql_query($query) ){
echo 'good';
}else{
echo mysql_error();
}
$disab = '' ;
$row = mysql_fetch_row($result);
if($choice==$row){
$disab = 'disabled';
}
<form id= "line" name="line " action="test1.php" method="post">
echo "<li> <input type='radio' name='placeInLine' id='choice1' $disab value='1' /> 10:00-10:15 </li>";
echo "<li> <input type='radio' name='placeInLine' id='choice2' $disab value='2' /> 10:15-10:30 </li>";
echo "<li> <input type='radio' name='placeInLine' id='choice3' $disab value='3' /> 10:30-10:45 </li>";
echo "<li> <input type='radio' name='placeInLine' id='choice4' $disab value='4' /> 10:45-11:00 </li>";
echo "<li> <input type='radio' name='placeInLine' id='choice5' $disab value='5' /> 11:00-11:15 </li>";
echo "<li> <input type='radio' name='placeInLine' id='choice6' $disab value='6' /> 11:15-11:30 </li>";
</form>
mysql_query("INSERT INTO $table(choice) VALUES ($choice)") or die(mysql_error());
$sqlinsert = "INSERT INTO placeinline (choice) VALUES ($choice)";
$newrecord = "1 choice added to the line";
echo $newrecord;
}
?>
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...