Link to home
Start Free TrialLog in
Avatar of BR
BRFlag for Türkiye

asked on

javascript form submition

Dear Experts,
I use a javascript to ask the user 'Are you sure?' before they submit the form

Below code works fine when my user clicks the submit button. But I want it to work just before the form is submitted. ( not onclick )

How can I do that? ( I know that I should use it on the <form tag like onSubmit  but I couldn't manage it)

<input type="submit" name="submit" id="submit" value="Submit" onclick="clicked(event)">

<script>
function clicked(e)
{
    if(!confirm('Are you Sure?'))e.preventDefault();
}
</script>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BR

ASKER

thank you