onSubmit return false not working - submit form by Javascript

I need to submit the form by using Javascript, but it seems the functions in onSubmit event don't work. When I click on Send link, the form is submitted, but I will not stay on the same page. It will redirect me to web page included in action attribute. Could you please tell me why is it not working ?

<form id="idmessage" name="message" method="post" onSubmit="javascript: alert('Form submitted'); return false;" action="index.php" >
<textarea name="content" ><textarea>
<br />
<a href="javascript:void(0);" onClick="javascript: document.getElementById('idmessage').submit(); " >Send</a>
</form>
0
give a positive ratinggive a negative rating
Hi,

The functions included in onSubmit event don't work, when you are using javascript function .submit() to submit the form. You have to call required javascript functions before document.getElementById('idmessage').submit();

For example:

<form id="idmessage" name="message" method="post" action="index.php" >
<textarea name="content" ><textarea>
<br />
<a href="javascript:void(0);" onClick="javascript: var valid = formValidation(); if(valid=='yes'){ alert('Form submitted'); document.getElementById('idmessage').submit(); }else { alert('Form not submitted'); } " >Send</a>
</form>
Share on FacebookShare on TwitterShare on LinkedInSend email
1 answer
x
x
2024 AnswerTabsTermsContact us