Reputation: 7080
JS:
$('#button6').click(function () {
$('#que1').hide();
$('#que2').hide();
$('#que3').hide();
$('#que4').show();
$('#que5').hide();
$('#que6').hide();
$('#que7').hide();
$('#que8').hide();
var line1 = $('.question3:checked').val();
if (typeof line1 === "undefined") {
var msg = new Windows.UI.Popups.MessageDialog("You Choosed", "nothing");
msg.showAsync();
$('#button6').click();
}
});
It is possible? I want to return the same function if does not check any radio button.
But this is not working.
Upvotes: 0
Views: 56
Reputation: 1200
If your condition if (typeof line1 === "undefined")
evaluates to true
, then you are in infinite loop. Because you are clicking the same button again.
$('#button6').click(function () {
some condition{
$( "#button6" ).trigger( "click" ); // Again triggering the same button click
}
}
If the checkbox is not checked you can show the alert, but do not call the same button click again. What you can do is you can prompt the user to check again.
Upvotes: 0
Reputation: 201447
Your approach is attempting to recurse... and is a terrible idea. Don't hide que3 until you've verified it's been answered. Show que4 then too. Consider the comments as well; that's how you could decorate question (e.g. add a red border).
var line1 = $('.question3:checked').val();
if (typeof line1 === "undefined") {
// $("que3").addClass('error');
return;
} else {
// $("que3").removeClass('error');
$('#que3').hide();
$('#que4').show();
}
Upvotes: 0
Reputation: 66113
Dangerous — if the condition is never satisfied, then you will be stuck in an infinite clicking loop.
Otherwise, use: $(selector).trigger("click")
.
Also, this line:
var line1 = $('.question3:checked').val();
if (typeof line1 === "undefined") { ... }
… can be simplified to:
if($('.question3').is('checked')) { .... }
Upvotes: 1