how to differentiate between javascript triggered submit and manually clicking form submit
sample code below
function myfunction()
{
document.getElementById("id_searchform").submit();
return true;
}
form:
<div class='row'>
<div class='col-md-4'>
<div class='clszipcode' ><span>Enter Zipcode</span></div>
</div>
<div class='col-md-4'>
<div class='clstxtzipcode' ><input type="text" name="zip_code" id="txtZipcode"></div>
</div>
<div class='col-md-4'>
<div class='clsbtnzip' ><input type="submit" name="submit" id="btnSearch" value="Search" class="button_example" ></div>
</div>
</div>
<a href="#" onclick="return myfunction();" >click to submit</a>
Put a hidden field. And when one of the buttons are clicked before submitting, populate the value of hidden field with like say 1 when first button clicked and 2 if second one is clicked. and in submit page check for the value of this hidden field to determine which one is clicked.
Submit a Form Using JavaScript The most simple way to submit a form without the submit button is to trigger the submit event of a form using JavaScript. In the below example we are going to create a function to submit a form. We will set that function at onclick event of a div tag.
5. Most HTML forms have a submit button at the bottom of the form. Once all of the fields in the form have been filled in, the user clicks on the submit button to record the form data. The standard behaviour is to gather all of the data that were entered into the form and send it to another program to be processed.
When we click on the link, the function submitForm() will get executed. This function will get the element object using DOM getElementById() method by passing the form id to this method, then the form will be submitted by using submit() method. Example: Create a form and submit it using the above approach.
Let me see if I understand:
validate()
which will use this information in some way.If this is the case, consider using a variable to store whether the link was clicked before triggering the form to submit.
wasClicked
to false
wasClicked
to true
wasClicked
is set.validate()
when form is submittedif(wasClicked){...}
in validate()
Here is a Working Example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With