Link to home
Create AccountLog in
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

Avatar of briankerrdesign
briankerrdesign
Flag of United States of America image

<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
Avatar of Big Monty
Big Monty
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of -Matthew-
-Matthew-

ASKER

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

Thanks