views:

38

answers:

2

Hi, I have a form that has two checkboxes, "A" and "B" and the form that is broken into steps. If "A" is checked and "B" isn't I need to display an alert when user clicks on the next step button, stopping the form from progressing only once,. like

if ($("#A").is(":checked") && $("B").is(":not("checked")") {
  alert("foo");
});

how do I make this happen only once, that is display the alert, user clicks "OK" to close alert and is allowed to progress on through the form? Thanks

A: 

Your condition should be like this:

if ($("#A").is(":checked") && $("B").is(":not(':checked')") {
 alert("foo");
});

Update:

Use the jQuery's one handler.

Sarfraz
Sorry about the syntax error, but back to the question, how do I get it to happen when user hits the next step button ("#step0Next") and only happen the first time they click on it?$("#step0Next").click(function() { if ($("A").is(":checked")
Dirty Bird Design
@Bird: Have a look at jquery `one` method: http://api.jquery.com/one/
Sarfraz
@Sarfraz, very good, just getting into that. thx
Dirty Bird Design
@Bird: You are welcome...
Sarfraz
@Sarfraz, is there something I'm missing? #step0Next is the button ID, $("#step0Next").one('click', function() { if($("#A").is(":checked") } });doesn't work
Dirty Bird Design
A: 
var userHasBeenAlerted = false;
if ($("#A").is(":checked") && $("B").is(":not(':checked')" && !userHasBeenAlerted) {
 userHasBeenAlerted = true;
 alert("foo");
});

Although I don't really follow what you mean with 'broken into steps', page reloads etc? If that is the case set it in a more global way (like a cookie or something)

Prot0