Jump to content

PHP coding Help on drop down list


usman07

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/261795-php-coding-help-on-drop-down-list/
Share on other sites

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).

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.