Replace select options via jQuery
Basically, I'm showing a select box on a page which holds values retrieved
from the database, I want to replace all these options based on other
values from the database when an action is fired from another form field,
here's what I currently have.
<select id="changePriceSets">
<option value="1">Price set 1</option>
<option value="2">Price set 2</option>
</select>
<select id="price" name="price" class="input-block-level">
<option value="25000">25,000</option>
<option value="50000">50,000</option>
<option value="100000">100,000</option>
<option value="200000">200,000</option>
<option value="300000">300,000</option>
</select>
I want to change the option values of the select box price when I fire
this jQuery function
$("select#changePriceSets").change(function(){
if($(this).find("option:selected").val() === "1") {
//update <select id="price" name="price"
class="input-block-level"> values to something like this
<option value="id from database">name from database</option>
<option value="id from database">name from database</option>
<option value="id from database">name from database</option>
} else if($(this).find("option:selected").val() === "2") {
//update <select id="price" name="price"
class="input-block-level"> values to something like this
<option value="id from database">name from database</option>
<option value="id from database">name from database</option>
<option value="id from database">name from database</option>
}
});
No comments:
Post a Comment