Reputation: 95
How do I change a message when I select different values from a select box using jquery.
<select name="myname">
<option value="rahul" selected>Rahul</option>
<option value="aisha">aisha</option>
</select>
If rahul
is selected show a message hello rahul
or if aisha
is selected then show a message hello aisha
Upvotes: 2
Views: 143
Reputation: 4389
Give an Id to your select box like
<select id ="op" name="myname">
<option value="rahul" selected>Rahul</option>
<option value="aisha">aisha</option>
</select>
then u can use some thing like this
$('#op').change(function(){
alert("Hello " + $(this).val());
});
Upvotes: 0
Reputation: 10350
$('select[name="myname"]').change(function() {
var selected = $(this).val();
$('.message').html(selected);
});
Give the box you want to have the message in the class selected
Upvotes: 0
Reputation: 50029
You can use the change() event
Here's a fiddle : http://jsfiddle.net/HjVxR/
$('[name="myname"]').change(function(){
$('#message').html('hello ' + $(this).val());
});
Upvotes: 2