php - Change select dropdown based on first select dropdown? -
i trying change second select dropdown based on whether first selected option contains (m) or (ft).
my form html search follows:
<form id="search" action="/property_search" method="get" class="clearfix"> <select name="sqsize" id="sqsize" class="sqsize"> <option value="">sq.ft/sq.m:</option> <option value="233.52m">233.52m</option> <option value="233.52m">233.52m</option> <option value="467.04m">467.04m</option> <option value="2,513ft">2,513ft</option> <option value="2,513ft">2,513ft</option> <option value="5,026ft">5,026ft</option> </select> <select name="sqsizemin" id="sqsizemin" class="sqsizemin"> <option value="">size min:</option> </select> <input type="submit" class="submit" value="search"> </form>
my jquery follows:
<script type="text/javascript"> $(function(){ $('#sqsize').change(function () { var options = ''; if($(this).val() == 'm') { options = '<option value=""></option>'; } else if ($(this).val() == 'ft') { options = '<option value="6">6</option>'; } $('#sqsizemin').html(options); }); $('#sqsize').trigger('change'); });
try this(using indexof
):
$(function(){ $("#sqsize").change(function(){ var options = ''; if($(this).val().indexof('m') > -1) { options = '<option value="">mm</option>'; } else if ($(this).val().indexof('ft') > -1) { options = '<option value="6">6</option>'; } $('#sqsizemin').html(options); }); });
Comments
Post a Comment