开发者

jquery help: how to get message after selecting radio button and select box

开发者 https://www.devze.com 2023-03-08 03:08 出处:网络
if i have selected one radio button and then if i select a value from select box I should get a message.

if i have selected one radio button and then if i select a value from select box I should get a message.

HTML:

First Class<input name="seat_class" id="a1" type="radio" value="First Class">
Second Class <input name="seat_class" id="a2" type="radio" value="Standard Class" />

 <select id="op" name="myname">
 <option value="none" selected>None</option>
<option value="rahul" selected>Rahul</option>
<option value="aisha">aisha</option>
</select> 

JavaScript:

$(document).ready(function(){


$('#a1').change(function() {

  $('#op').change(function(){
      if($(this).val()==rahul)
      {
alert("Hello yar " + $(this).val());
      }
});

  //alert('foo');

});

$('#a2').change(function() {
  alert('bar');

});

$('#op').change(function(){
alert("Hello " + $(this).val()开发者_StackOverflow中文版);
});

})

This code is not working any how.

I want that when i select radio button 1 and rahul i should get a message, and if i select radio button 2 and aisha i should get another message. Please help.


http://jsfiddle.net/jX5uT/

Hope that helps.

You cant bind to events inside of other event bindings. You can however use a selector to do other things inside of a binding.


This should get you the basics:

$(document).ready(function(){
    $("input[type=radio]").click(function(){
        if($("#a1").is(":checked")) { 
            $('#op').change(function(){       
                if($(this).val()== "rahul"){ 
                    alert("Hello yar " + $(this).val());       
                } 
            }); 
        }   
    });
});

Don't forget "rahul" needs to be in quotes otherwise it will think it is a variable.

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消