kabucek Posted March 30, 2009 Share Posted March 30, 2009 hello @LL, I have some dropdown <select name='selectedProd'> <option value='code1'>event 1,IL</option> <option value='code2'>event 2, IL</option> I want to create checkbox visible only if user picks event 1 from dropdown, but checkbox would not show up if event 2 will be selected. is that possible? thanks Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/ Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 Do you want this with or without the page loading. If you are okay with the page loading, we can help on this board. If you don't want the page to reload, jump over to the JS board. Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797201 Share on other sites More sharing options...
kabucek Posted March 30, 2009 Author Share Posted March 30, 2009 reload will cause refresh, right? yes please make your suggestion on how this could be solved thank you Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797204 Share on other sites More sharing options...
lonewolf217 Posted March 30, 2009 Share Posted March 30, 2009 this would be done using onSelect with Javascript Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797222 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 lonewolf, and then use ajax to built the checkbox or use simple js to change the style.display of the element? Either would work, but this isn't the board for JS. Kabucek, this seems to be a good time to use js, but if you want to go pure html and php, here is what you can do. They will need to select from the drop down then submit the form. interchange $_GET for $_POST if you are using form method = post <option value='code1'>event 1,IL</option> <option value='code2' <?php if($_GET['selectedProd'] == "code2"){ echo "selected"; } ?>>event 2, IL</option> </select> <?php if($_GET['selectedProd'] == 'code1'){ echo "Box here <input type='checkbox' name='check' value='1'>"; } ?> you'll probably need to make several adjustments, but essentially that is what you could do. Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797235 Share on other sites More sharing options...
kabucek Posted March 30, 2009 Author Share Posted March 30, 2009 this looks good, i will try that now, but maybe you're right about js, because I would want that to be dynamic, if event 1 is selected the checkbox will show up for them without submitting the whole form. Thanks !! Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797240 Share on other sites More sharing options...
Brian W Posted March 30, 2009 Share Posted March 30, 2009 then js would be the best bet. If you post in the JS board and don't get replies w/in a reasonably amount of time, PM me and I'll go help you out (I don't hang around the JS board often) Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797257 Share on other sites More sharing options...
Andy-H Posted March 30, 2009 Share Posted March 30, 2009 <select name"selectedProd" onChange="if (this.selectedIndex == 1){ document.getElementById('chkBoxDisp').innerHTML = '<input type=checkbox>'; }else{ document.getElementById('chkBoxDisp').innerHTML = ''; }" > <option value="">...</option> <option value="code1">event 1,IL</option> <option value="code2">event 2, IL</option> </select> <div id="chkBoxDisp" style="width: 100%; height: 15px; background-color: #ffffff;"><!-- CHECKBOX --></div> That should do it:P Quote Link to comment https://forums.phpfreaks.com/topic/151823-create-checkbox-when-choice-is-made-from-dropdown/#findComment-797286 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.