Reputation: 1632
I am using following code snippter on button click event. Issue is if I don't select radio button than it gives me alert undefined but if I use same condition that is if I equate value of same in if condition than it escape condition.
From below code I am not getting alert("Select action to perform.");
as this if condition is skipped.
$('#actionbutton').click(function(){
alert('HI SANKALP');
var manageradiorel = $('input[name="managerelradio"]:checked').val();
var parentid = <?php echo $parentid; ?>;
var childid = $('#managechild').val();
var sgid = <? echo $_GET["s"]; ?>;
var relationship = $('#childsgrel').val();
alert(manageradiorel);
if(manageradiorel == "undefined"){
alert("Select action to perform.");
return false;
}
alert("Next time");
});
Upvotes: 1
Views: 450
Reputation: 54638
in Javascript there are two optimal ways to determine if a variable exists. One is more descriptive than the other.
if (manageradiorel)
if (typeof manageradiorial == "undefined")
Update:
If you have access to Jquery 1.6 or higher, I highly recommend using the jQuery prop() method instead of val();
Upvotes: 2
Reputation: 430
Try changing if(manageradiorel == "undefined")
to if(manageradiorel === undefined)
Upvotes: 1