Hey, Ok, I have a booking table and all days & times are in a select box: eg. <select name="setmain" size="25" id="setmain" onclick="checkItems();"> <option value="Mon-1" >Monday at 1 AM (GMT) </option> <option value="Mon-2" >Monday at 2 AM (GMT) </option> <option value="Mon-3" >Monday at 3 AM (GMT) </option> <option value="null" disabled="disabled">Monday at 4 AM (GMT) already booked</option> <option value="Mon-5" >Monday at 5 AM (GMT) </option> <option value="Mon-6" >Monday at 6 AM (GMT) </option> ...... </select> Code (markup): On the previous page, the person is asked to book 1 to 4 hours. Ok, what I need is to check the select box options, say they chose 4 hours and then they click 2 am or 3 am (which can't be booked as 4am is already booked), I want it to alert them that this time cant be booked and deactivate that value. I thought of putting null as every booked would be easier to check (if value = null then blah).... function checkItems() { var length = <? echo $length; ?>; var opt = document.getElementById("setmain").value; var optid = document.getElementById("setmain").selectedIndex; var x = 0; for (i = 0; i < length; i++) { // am stuck here // if value = null then blah sorta thing } } Code (markup): $length is 1 to 4 by the way Any thoughts? TIA
Hi usually if a select box has disabled items that means that the user cannot select them. if the item was not disabled you could do something like this <select name="setmain" size="25" id="setmain" onchange="check(this);"> <option value="Mon-1" >Monday at 1 AM (GMT) </option> <option value="Mon-2" >Monday at 2 AM (GMT) </option> <option value="Mon-3" >Monday at 3 AM (GMT) </option> <option value="null" >Monday at 4 AM (GMT) already booked</option> <option value="Mon-5" >Monday at 5 AM (GMT) </option> <option value="Mon-6" >Monday at 6 AM (GMT) </option> ...... </select> function check(selObj){ var optid = document.getElementById("setmain").selectedIndex; if (selObj.options[optid].value=="null"){ alert("booking is not posible"); } }
If they chose a 3hr booking at 2am, then I would need to go (loop) through all the 3am, 4am & 5am to see if theyre null, in this case 4am is, thus need to flag it, if you get me? Just wondered if this is possible..... booked sets are disabled anyway, so theyre unselectable.