I have two radio buttons like so
<input type='radio' name='rush' value='yes' /> <input type='radio' name='rush' value='no' checked='checked' />
What I want to do is when the form submit button is clicked, check if ‘yes’ is selected.
If it is, show a javascript confirm dialog
I’ve gotten this far, but am stuck, any help would be appreciated.
$('form.shipping').submit(function() { if($('input[name='rush']'.attr('value') === 'yes') { if (confirm('Rush orders are subject to an upcharge. (Just wanted to make sure you read the note). Is this ok?')) { return true; } else { return false; } } });
You are binding something to the
clickevent of a button. You probably want to bind it to thesubmitevent of the form. Besides that, you misspelledinput.sumbit-buttonin your selector.EDIT: Here is a working version of what you want. Your errors were:
document.ready. This is important if your script is included at the top of the page, as anything you write that is not wrapped in this event will execute before the DOM elements are created. So you would be binding events to nothing. Thedocument.readyevent takes care of that by firing as soon as the DOM is fully loaded.)right before.attr. You should probably look into tools like FireBug to debug your javascript, as it is trivial to find these kind of things with it.:checkedone.So, the working code: