Reputation: 3
ok, so I'm a complete noob when it comes to jQuery, but this is something I want to change over the next year or so if I can find the time!!
I have the following for the dropdown options
<select id="shipping_method_id" name="shipping_method_id">
<option value="6">North Island - New Zealand</option>
<option value="7">South Island - New Zealand</option>
<option value="8">Australia</option>
</select>
What I want to have is when someone selects Australia from the list I want it to show a div.
When someone selects an option from the list, the page reloads and updates the shipping price.
This is probably really really simple, but I just can't get it working, I've tried this http://jsfiddle.net/JSyLV/910/ but it won't work :(
Upvotes: 0
Views: 167
Reputation: 3082
You need to use the jQuery .change event.
jQuery('#shipping_method_id').change(function(){
if(jQuery(this).val() === '8' ){
jQuery("#hide_my_ass").slideDown();
}
});
http://jsfiddle.net/JSyLV/920/
EDIT
jQuery('#shipping_method_id').change(function(){
window.location = window.location + '?postPrice=' + jQuery(this).val();
});
Then in PHP you have access to the get variable $_GET['postPrice'] which you can then output as the price. http://jsfiddle.net/JSyLV/931/
Upvotes: 0
Reputation: 36531
try this
$('#shipping_method_id').change(function(){ //call the change function
if($(this).val()==8){ //check if selected val is 8 (australia)
$('#hide_my_ass').show(); //if yes show
}else{
$('#hide_my_ass').hide(); //else hide
}
});
http://jsfiddle.net/JSyLV/928/
Upvotes: 0
Reputation: 103338
You need to add an event listener to call this code:
$("#shipping_method_id").change(function(){
if($(this).val() == '8'){
$("#hide_my_ass").slideDown();
}
});
http://jsfiddle.net/JSyLV/913/
Upvotes: 1