Jump to content

if Value =


01hanstu

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/133180-if-value/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692662
Share on other sites

Java and JavaScript are different. :P 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.

Link to comment
https://forums.phpfreaks.com/topic/133180-if-value/#findComment-692685
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.