01hanstu Posted November 4, 2010 Share Posted November 4, 2010 Hi, I have a dropdown box, and I want it so that if dropdownbox.value='selected:' then show error message. The checkbox is dynamically populated. Pleaee Advise, - stuart Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2010 Share Posted November 4, 2010 Post your code. Quote Link to comment Share on other sites More sharing options...
01hanstu Posted November 4, 2010 Author Share Posted November 4, 2010 Hi, Sorry. This is the existing code: <? $getroomsquery = "SELECT * from rooms"; $getroomresults = mysql_query($getroomsquery); $getroomcount = mysql_num_rows($getroomresults); $loop = 0; ?> <form name="roomform" method="post" action="bookingindex.php?week=<? print $mondaythisinstance ?>"> <select name="selectroom" class="formnames"> <option value=" <?PHP print $room ?>" selected>Selected: <?PHP print $room ?></option> <option value="">- - - - - - - - - - -</option> <? while ($loop < $getroomcount) { print"<option value=\"".mysql_result($getroomresults,$loop,"roomname")."\">".mysql_result($getroomresults,$loop,"roomname")."</option>"; $loop ++; } ?> </select> <input name="Submit" type="submit" class="formnames" value="Go"> </div> </form>< The issue is that when it populated the dropdown box, i added the part to show the 'Selected:Room1' room, but some people are just clicking submit, and it tries to show the room 'Selected:Room1', which doesn't exist, whereas room1 does. Please Advise, - Stuart Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2010 Share Posted November 4, 2010 The best way to do it would be to check if the form field is set, and its value is in the array of values that were used to build the list of <options>, but absent that list, this is the best I can do for the moment . . . if( isset($_POST['selectroom']) && $_POST['selectroom'] != "" ) { // a value is set, so do something. } else { // no value is set, so kick out an error. } Quote Link to comment 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.