usman07 Posted April 29, 2012 Share Posted April 29, 2012 Basically I have a form and What I want it to do is when a user selects the 'For Sale' radio button the minimum and maximum prices will be displayed in the drop down list as "70,000"+ but when the user selects the 'To Rent' radial button then the minimum and maximum drop down list prices will change to e.g. "200"+. How would I do this? Heres my Code for the form: <div id="ptype"> <input type="radio" class="styled" name="ptype" value="forsale"/> For Sale <p class="increase"> <input type="radio" class="styled" name="ptype" value="forrent"/> To Rent </p> <p class="increase"> <input type="radio" class="styled" name="ptype" value="any"/> Any </p> </div> </td> </tr> </table> <div id="table2"> <table id="NBtable"> <tr> <td><p class="NBS">Number of bedrooms:</p></td> <td><div id="NB"> <select name="min bedrooms"> <?php $roomLimit = 5; for($minRooms = 0; $minRooms <= $roomLimit; $minRooms++){ if ($minRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value=\"$minRooms\">$minRooms</option>"; } } ?> </select> to <select name="max bedrooms"> <?php $roomLimit = 5; for($maxRooms = 0; $maxRooms <= $roomLimit; $maxRooms++){ if ($maxRooms == 0){ echo"<option value=\"0\" selected=\"selected\">No Max</option>"; } else{ echo "<option value=\"$maxRooms\">$maxRooms</option>"; } } ?> </select> </div> </td> <td><p class="PR">Price range:</p></td> <td><div id="PR"> <select name="min price" style='width:80px;'> <?php $priceLimit = 350; for($minPrice = 40; $minPrice <= $priceLimit; $minPrice =( $minPrice+ 10)){ if ($minPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Min</option>"; } else{ echo "<option value=\"$minPrice000\">£$minPrice,000</option>"; } } ?> </select> to <select name="max price" style='width:80px;'> <?php $priceLimit = 350; for($maxPrice = 40; $maxPrice <= $priceLimit; $maxPrice =( $maxPrice+ 10)){ if ($maxPrice == 40){ echo"<option value=\"0\" selected=\"selected\">No Max</option>"; } else{ echo "<option value=\"$maxPrice000\">£$maxPrice,000</option>"; } } ?> </select> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/261795-php-coding-help-on-drop-down-list/ Share on other sites More sharing options...
MMDE Posted April 29, 2012 Share Posted April 29, 2012 Unless you want the user to submit the form data after selecting the radio button, I'd say you need to use JavaScript. If you want to make it easier, you could load the prices along with everything else, but if there's a lot of items, you may want to look into combining your JavaScript with Ajax (JSON). Quote Link to comment https://forums.phpfreaks.com/topic/261795-php-coding-help-on-drop-down-list/#findComment-1341516 Share on other sites More sharing options...
usman07 Posted April 29, 2012 Author Share Posted April 29, 2012 How would I use javascript and Ajax?Thanks Quote Link to comment https://forums.phpfreaks.com/topic/261795-php-coding-help-on-drop-down-list/#findComment-1341524 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.