Avatar of -Matthew-
-Matthew- asked on

Multiple Submit buttons

Is it possible to have two submit buttons, one that runs javascript and one that submits without running the script or just by passes the validation.

I know I could just put an image there and send them on, but if I can just say submit and move on using the same form. I guess this is more of curiosity question.

Thanks
<script type="text/javascript" language="javascript">
	function validateForm()
{
var x=document.forms["myForm"]["guardian_household"].value
var y=document.forms["myForm"]["guardian_tanf"].value
if (x==null || x=="" || y==null || y=="")
  {
  alert("All fields required.");
  return false;
  } 
  
}
</script>

<form name="myForm" action="" onsubmit="return validateForm()" method="post">
Name: <input type="text" name="guardian_household" id="guardian_household" /><br />
Tanf: <input type="text" name="guardian_tanf" id="guardian_tanf" />

<input name="answers" type="submit" class="submitbutton" id="answers" value="Submit Case Number and continue" />

<input name="answers" type="submit" class="submitbutton" id="answers" value="I Do Not Have A TANF / Food Stamp Case " />

</form>

Open in new window

JavaScript

Avatar of undefined
Last Comment
-Matthew-

8/22/2022 - Mon
briankerrdesign

<script type="text/javascript" language="javascript">
	function validateForm()
{
var x=document.forms["myForm"]["guardian_household"].value
var y=document.forms["myForm"]["guardian_tanf"].value
if (x==null || x=="" || y==null || y=="")
  {
  alert("All fields required.");
  return false;
  } else{
  document.forms["myForm"].submit();
}
  
}
</script>

<form name="myForm" action="" method="post">
Name: <input type="text" name="guardian_household" id="guardian_household" /><br />
Tanf: <input type="text" name="guardian_tanf" id="guardian_tanf" />

<input name="answers" type="submit" class="submitbutton" id="answers" value="Submit Case Number and continue" />

<input name="answers" type="button" class="submitbutton" id="answers_2" value="I Do Not Have A TANF / Food Stamp Case " onClick="validateForm()" />

</form>

Open in new window

ASKER CERTIFIED SOLUTION
Big Monty

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
-Matthew-

@The_big_daddy OH too easy, why didn't I think of that. Its sometimes the easy answers that get over looked.

Thanks
Your help has saved me hundreds of hours of internet surfing.
fblack61