HTML button onClick listener calling HTML form onSubmit javascript function

kittu88

I am a novice in web development, I have created a simple html page. The page has two buttons, Submit and Display Data. The Submit button is supposed to post form data to a particular page after validating the form. This button is working fine. I am facing a problem with the Display Data button. The button is supposed to open a separate page and there should not be any kind of form validation. The page is getting open but the form is also getting validated.

The html page:

<html>
<head>
<script>
function validateForm()
{
var name=document.forms["myForm"]["name"].value;
var email=document.forms["myForm"]["email"].value;
var mobile=document.forms["myForm"]["mobile"].value;
var address=document.forms["myForm"]["address"].value;
var atpos=email.indexOf("@");
var dotpos=email.lastIndexOf(".");
if (name==null || name=="")
  {
  alert("Name must be filled out");
  return false;
  }

else if (atpos<1 || dotpos<atpos+2 || dotpos+2>=email.length)
  {
  alert("Not a valid e-mail address");
  return false;
  }

  else if(isNaN(mobile)||mobile.indexOf(" ")!=-1)
  {
  alert("Enter numeric value")
  return false; 
  }
  else if (mobile.length != 10)
  {
  alert("Enter 10 digit mobile");
  return false;
  }
  else if (mobile.charAt(0)=="0")
  {
  alert("Mobile no should not start with 0");
  return false;
  }
  else if (address==null || address=="")
  {
  alert("Address must be filled out");
  return false;
  }

}
</script>

</head>

<body>
<h2>Employee Details Entry</h2>
<form name="myForm" action="insertDisplay.php" onSubmit="return validateForm()" method="post">
Name: <input type="text" name="name"><br/>
Email: <input type="text" name="email"><br/>
Mobile: <input type="text" name="mobile"><br/>
Address: <input type="text" name="address"><br/>
<input type="submit" value="Submit"> <button onClick="location.href = 'insertDisplay.php'">Display Data</button>
</form>

</body>

</html>

Where am I going wrong? Why is the form validation function getting called?

user1844933

place <button onClick="location.href = 'insertDisplay.php'">Display Data</button> this line out of the form...

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Javascript + HTML: Button Not Calling on Function Onclick

From Dev

Javascript + HTML: Button Not Calling on Function Onclick

From Dev

HTML onsubmit event is not calling the JavaScript function

From Dev

HTML form submit not calling Javascript "onsubmit" handler in Wordpress post

From Dev

Simple form onsubmit not calling javascript function (JQuery)

From Dev

Simple HTML Javascript button onclick function not working

From Dev

Javascript create button and trigger onclick function on HTML

From Dev

button and onclick - Html, javascript

From Dev

Issue with HTML form submit button not calling Google script function

From Dev

Calling JavaScript function ping() in onClick of an HTML hyperlink tag results in TypeError

From Dev

How to work with Enter Button and onclick in Javascript HTML form

From Dev

html onsubmit doesn't start Javascript function

From Dev

html ,javascript onclick event listener Dom

From Dev

HTML-form submit button not running the OnSubmit script associated with it

From Dev

HTML-form submit button not running the OnSubmit script associated with it

From Dev

Calling server function onclick and returning templated html

From Dev

Calling server function onclick and returning templated html

From Dev

Will adding onclick in HTML and calling from Javascript conflict?

From Dev

javascript function and html onclick property

From Dev

How do I validate this HTML/JavaScript form onsubmit?

From Dev

Calling PHP function wth HTML button

From Dev

Calling a C# function by a HTML button

From Dev

Calling a JS function with HTML form data

From Dev

Button onclick function in HTML keeps resetting the form input fields to default values. How can I avoid this?

From Dev

Trouble Integrating JavaScript into HTML with button onClick event

From Dev

html button onclick start javascript progressbar

From Dev

HTML Javascript - Replace a button with a search field onclick

From Dev

UDF Javascript not called from HTML button onclick

From Dev

Add JavaScript onclick() to HTML form submit

Related Related

  1. 1

    Javascript + HTML: Button Not Calling on Function Onclick

  2. 2

    Javascript + HTML: Button Not Calling on Function Onclick

  3. 3

    HTML onsubmit event is not calling the JavaScript function

  4. 4

    HTML form submit not calling Javascript "onsubmit" handler in Wordpress post

  5. 5

    Simple form onsubmit not calling javascript function (JQuery)

  6. 6

    Simple HTML Javascript button onclick function not working

  7. 7

    Javascript create button and trigger onclick function on HTML

  8. 8

    button and onclick - Html, javascript

  9. 9

    Issue with HTML form submit button not calling Google script function

  10. 10

    Calling JavaScript function ping() in onClick of an HTML hyperlink tag results in TypeError

  11. 11

    How to work with Enter Button and onclick in Javascript HTML form

  12. 12

    html onsubmit doesn't start Javascript function

  13. 13

    html ,javascript onclick event listener Dom

  14. 14

    HTML-form submit button not running the OnSubmit script associated with it

  15. 15

    HTML-form submit button not running the OnSubmit script associated with it

  16. 16

    Calling server function onclick and returning templated html

  17. 17

    Calling server function onclick and returning templated html

  18. 18

    Will adding onclick in HTML and calling from Javascript conflict?

  19. 19

    javascript function and html onclick property

  20. 20

    How do I validate this HTML/JavaScript form onsubmit?

  21. 21

    Calling PHP function wth HTML button

  22. 22

    Calling a C# function by a HTML button

  23. 23

    Calling a JS function with HTML form data

  24. 24

    Button onclick function in HTML keeps resetting the form input fields to default values. How can I avoid this?

  25. 25

    Trouble Integrating JavaScript into HTML with button onClick event

  26. 26

    html button onclick start javascript progressbar

  27. 27

    HTML Javascript - Replace a button with a search field onclick

  28. 28

    UDF Javascript not called from HTML button onclick

  29. 29

    Add JavaScript onclick() to HTML form submit

HotTag

Archive