robert_gsfame Posted October 5, 2009 Share Posted October 5, 2009 i want users only allowed to tick one checkbox only..so if they tick one checkbox (let say i have 2 checkboxes) then it will clear the other one Can anyone help me solve this simple problem Thanks in advance Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/ Share on other sites More sharing options...
jon23d Posted October 5, 2009 Share Posted October 5, 2009 Use radio buttons instead, this is their purpose. Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930588 Share on other sites More sharing options...
Jibberish Posted October 5, 2009 Share Posted October 5, 2009 You probably want to use radio buttons for this, and make sure that they all have the same name. When a user selects one the browser will uncheck the others with the same name. Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930589 Share on other sites More sharing options...
robert_gsfame Posted October 5, 2009 Author Share Posted October 5, 2009 but i want to use checkbox instead of using radiobutton Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930590 Share on other sites More sharing options...
Bricktop Posted October 5, 2009 Share Posted October 5, 2009 Hi robert_gsfame, You can't do this with checkboxes without using some Javascript. I'd recommend you use radio buttons as they're mutually exclusive. If you must use checkboxes and Javascript, here's some sample code I found after a quick Google search: <script language="javascript"> function SingleSelect(regex,current) { re = new RegExp(regex); for(i = 0; i < document.forms[0].elements.length; i++) { elm = document.forms[0].elements[i]; if (elm.type == 'checkbox') { if (re.test(elm.name)) { elm.checked = false; } } } current.checked = true; } </script> </HEAD> <body> <form id="Form1" method="post" > <table width="100%" align="center"> <tr> <td> <br/>aaaa<input type="checkbox" id="chkOne" name="chkOne" value="aaaa" checked onclick="SingleSelect('chk',this);" /> <br/>bbbb<input type="checkbox" id="chkTwo" name="chkTwo" value="bbbb" onclick="SingleSelect('chk',this);" /> <br/>cccc<input type="checkbox" id="chkThree" name="chkThree" value="cccc" onclick="SingleSelect('chk',this);" /> <br/>dddd<input type="checkbox" id="chkFour" name="chkFour" value="dddd" onclick="SingleSelect('chk',this);" /> <br/>eeee<input type="checkbox" id="chkFive" name="chkFive" value="eeee" onclick="SingleSelect('chk',this);" /> </td> </tr> <tr> <td></td> </tr> <tr> <td></td> </tr> </table> </form> </body> </HTML> Hope this helps. Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930592 Share on other sites More sharing options...
robert_gsfame Posted October 5, 2009 Author Share Posted October 5, 2009 thx bricktop !! Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930597 Share on other sites More sharing options...
ILMV Posted October 5, 2009 Share Posted October 5, 2009 Whether you want to use check boxes of not, a user will always expect to only choose one option from a radio button, and multiple options with a check box, so be careful, you might have a usability issue there. Link to comment https://forums.phpfreaks.com/topic/176538-dynamic-checkbox-simple-problem/#findComment-930608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.