sama Posted March 12, 2010 Share Posted March 12, 2010 Hello forum please I have this problem: I have a group of radio buttons, when the user select one of them, this radio button should be removed ( or become passive )..how could I do that? I really need help.. sama Baghdad-Iraq This is my code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> <p> <label> <input type="text" name="t1" id="textfield" /> </label> </p> <p> <input type="radio" name="check" value="2010-03-12 00:00:00"> 2010-03-12 00:00:00<br> <input type="radio" name="check" value="2010-03-12 02:00:00"> 2010-03-12 00:02:00<br> <input type="radio" name="check" value="2010-03-12 04:00:00"> 2010-03-12 00:04:00<br> <input type="radio" name="check" value="2010-03-12 06:00:00"> 2010-03-12 00:06:00</p> <p> <label> <input type="submit" name="b1" id="button" value="Submit" /> </label> <br> </p> </form> <?php $cxn = mysqli_connect("localhost","root","","nana") or die("Query died: connect"); if (isset($_POST['b1'])) { $username=$_POST['t1']; $selection=$_POST['check']; $sql="INSERT INTO test (username,time) VALUES ('$username','$selection')"; mysqli_query($cxn,$sql); } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/ Share on other sites More sharing options...
aebstract Posted March 12, 2010 Share Posted March 12, 2010 If you want it to go away right when they check it, you're going to have to use javascript. If you want to do it after they click a submit button, you can check to see if that field entry is checked or not to determine if it gets displayed. I don't do javascript so I couldn't help you there. Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025361 Share on other sites More sharing options...
teamatomic Posted March 12, 2010 Share Posted March 12, 2010 Thats not the way a group of radio buttons is designed to function. When a group of buttons have the same name selecting one will result in whatever one is currently selected to unselect. As to why its not practical, if a button is selected and it hides then if it was pushed by accident how would the user get it back? You might be better served using checkboxes. What exactly are you trying to accomplish? HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025374 Share on other sites More sharing options...
sama Posted March 13, 2010 Author Share Posted March 13, 2010 Thats not the way a group of radio buttons is designed to function. When a group of buttons have the same name selecting one will result in whatever one is currently selected to unselect. As to why its not practical, if a button is selected and it hides then if it was pushed by accident how would the user get it back? You might be better served using checkboxes. What exactly are you trying to accomplish? HTH Teamatomic Thanks aebstract for your replay.. Hello teamatomic this is what I want to do: when the user select one of these time slots ( he can't select more than one slot so I don't use check box ), & after he press the submit button, the selected radio button must become passive ( gray one, not active )..the selected slot is stored in a database ( no one should select the same time slot , so I want to make it passive).. hope you catch what I mean... I need help plz Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025598 Share on other sites More sharing options...
teamatomic Posted March 13, 2010 Share Posted March 13, 2010 You just show the already selected time grayed and without a button. You can store the times in an array in a session var and use it to compare against the times when you build the form. HTH Teamatomic Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025627 Share on other sites More sharing options...
sama Posted March 13, 2010 Author Share Posted March 13, 2010 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> <p> <label> <input type="text" name="t1" id="textfield" /> </label> </p> <p> <?php $time_slots= array ("t1"=>"2010-03-13 00:00:00","t2"=>"2010-03-13 02:00:00", "t3"=>"2010-03-13 04:00:00","t4"=>"2010-03-13 06:00:00", "t5"=>"2010-03-13 08:00:00","t6"=>"2010-03-13 10:00:00"); foreach ($time_slots as $time => $value) { echo "<input type='radio' name='check' value='$value' >$value<br>" ; echo "</br>"; } ?> <br /> <input type="submit" name="b1" id="button" value="Submit" /> </label> <br> </p> </form> <?php $cxn = mysqli_connect("localhost","root","","nana") or die("Query died: connect"); if (isset($_POST['b1'])) { $username=$_POST['t1']; $selection=$_POST['check']; $sql="INSERT INTO test (username,time) VALUES ('$username','$selection')"; mysqli_query($cxn,$sql); } ?> <body> </body> </html> Hello teamatomic Thanks for your replay... I do what you said...but still the comparison issue..I will try my best & please help me in ideas too.. sama Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025636 Share on other sites More sharing options...
sama Posted March 13, 2010 Author Share Posted March 13, 2010 The problem is solved!! here is the code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <form id="form1" name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']?>"> <p> <label> <input type="text" name="t1" id="textfield" /> </label> </p> <p> <?php $cxn = mysqli_connect("localhost","root","","nana") or die("Query died: connect"); $sql = "SELECT slot FROM times"; $result= mysqli_query($cxn,$sql)or die("Query died: Username"); while ($row=mysqli_fetch_array($result)) { $value=$row['slot']; echo "<input type='radio' name='check' value='$value' >$value<br>" ; echo "</br>"; } if (isset($_POST['b1'])) { $username=$_POST['t1']; $selection=$_POST['check']; $sql="INSERT INTO test (username,time) VALUES ('$username','$selection')"; mysqli_query($cxn,$sql); $sql1 = "SELECT slot FROM times"; $result1= mysqli_query($cxn,$sql1)or die("Query died: Username"); while ($row=mysqli_fetch_array($result1)) { $sql1="DELETE FROM times WHERE slot='$selection' "; mysqli_query($cxn,$sql1); } } ?> <br /> <input type="submit" name="b1" id="button" value="Submit" /> </label> <br> </p> </form> <body> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/195056-remove-a-radio-button/#findComment-1025678 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.