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 Link to comment https://forums.phpfreaks.com/topic/217735-dropdown-box-help/ Share on other sites More sharing options...
Pikachu2000 Posted November 4, 2010 Share Posted November 4, 2010 Post your code. Link to comment https://forums.phpfreaks.com/topic/217735-dropdown-box-help/#findComment-1130293 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 Link to comment https://forums.phpfreaks.com/topic/217735-dropdown-box-help/#findComment-1130338 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. } Link to comment https://forums.phpfreaks.com/topic/217735-dropdown-box-help/#findComment-1130341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.