Submit button confirmation?

I’m noob at javascript

How should I do this?

I have this form with submit button.
What I want is when I press the submit button the confirmation windows with
YES or NO should appear first.

If I press yes It should go ahead and do the normal process.
And If I will press NO it should stay and don’t do anything.

How to do this in javascript?

Thanks in advanced.

<a href="javascript: if (confirm(‘Continue?’)) { window.location.href=‘google.com’ } else { void(‘’) }; ">I Agree</a>

change the google.com to your site/link whatever, and the I Agree is the link title

Please don’t mix JavaScript in with your HTML code.

Here is a sample form:


<form id="registerUser">
    ...
    <p><input type="submit" value="Register User"></p>
</form>

We can attach a function on to the onsubmit event of the form, which is triggered by the submit button.

script.js


var form = document.getElementById('registerUser');
form.onsubmit = function () {
    // this method is cancelled if window.confirm returns false
    return window.confirm('Are you sure that you want to submit this form?');
}

Here’s how it might look when put together:


<html>
...
<body>
<form id="registerUser">
    ...
    <p><input type="submit" value="Register User"></p>
</form>

<script type="text/javascript" src="script.js"></script>
</body>
</html>

but what if the user press ok? what wheres the redirect link?

If the OK button is pressed, that will result in a true value from the confirm dialog. The onsubmit event is only cancelled when false is returned, so with true being returned the form will submit as per normal.

The original poster says nothing about a redirect link. I think that might be a misunderstanding that is occurrring.