01hanstu Posted November 18, 2008 Share Posted November 18, 2008 Hi, hope you can help. Just want to know if it is possible to add a bit to my script that, when a value is shown in the menu/Dropdown box the go button is disabled. i.e. if dropdownbox1 = "Selected:IT1" then Disable go button else keep button enabled. My app is a booking app and when the user selects the room from the dropdown list and clicks go it takes them to the room timetable, however i added a bit that tells you what room you are in at the top of the combo list, but if the user clicks go it brings them an empty timetable and i dont want that to happen. Many Thanks Stuart Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/ Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 You would need to use Javascript or Ajax. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692654 Share on other sites More sharing options...
monkeytooth Posted November 18, 2008 Share Posted November 18, 2008 You wouldnt need java for that, unless your looking to update on the fly without loading/reloading the page. If on the pages initial load its loading existing data from something else be it a database or from a prior $_post $_get or $_session or $_cookie, or something of that nature you can just do an if else then like statement in the button ie: <input type="submit" value="Submit" name="Submit_Button"<?php if($dropdownbox1 == "Selected:IT1") { echo " disabled=\"disabled\""; } else { echo ""; } ?>> of course you would have to define the $dropdownbox1 as a variable else where to know what its doing in the first placed based off the input that would disable the button in the first place. However, on the flip side like revraz said, if your going to select from the drop down, and then have it based on that disable the button then your going to need javascript. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692662 Share on other sites More sharing options...
revraz Posted November 18, 2008 Share Posted November 18, 2008 Reading his post, sure sounds like he wants to. You wouldnt need java for that, unless your looking to update on the fly without loading/reloading the page. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692663 Share on other sites More sharing options...
JasonLewis Posted November 18, 2008 Share Posted November 18, 2008 Java and JavaScript are different. And it would require JavaScript. if the user clicks go it brings them an empty timetable and i dont want that to happen. The basic code: <script type="text/javascript"> function selectupdate(n){ var invalids = new Array("Selected:IT1"); //An array of all the rooms that have no timetable. var change = false; var option = n.options[n.options.selectedIndex].value; for(var i = 0; i < invalids.length; ++i){ if(option == invalids[i]) change = true; } if(change){ document.getElementById("submit").disabled = 'disabled'; }else{ document.getElementById("submit").disabled = ''; } } </script> <select name="room" id="room" onchange="javascript: selectupdate(this)"> <option value="Selected:PE1">PE1</option> <option value="Selected:IT1">IT1</option> <option value="Selected:IT2">IT2</option> </select> <input type="submit" name="submit" id="submit" value="Go!" /> However, I would also provide an alternative if you think there is the chance that someone without JavaScript enabled will be using your website. If you are confident you don't need to, then don't bother. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692685 Share on other sites More sharing options...
01hanstu Posted November 20, 2008 Author Share Posted November 20, 2008 Thanks for you help. I dunno if they will work as the information is pulled from the sql database, and is not actually on the form. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-694613 Share on other sites More sharing options...
DeanWhitehouse Posted November 20, 2008 Share Posted November 20, 2008 Should still work. Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-694629 Share on other sites More sharing options...
01hanstu Posted November 24, 2008 Author Share Posted November 24, 2008 Thanks for your help, will implement asap and get back to you, thanks Quote Link to comment https://forums.phpfreaks.com/topic/133180-if-value/#findComment-697565 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.