Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q924 How can I pass a hidden value to a form and submit that form when a text link is clicked?

You are here: irt.org | FAQ | JavaScript | Form | 3.1 | Q924 [ previous next ]

Try:

<form name="myForm">
<input type="hidden" name="myHiddenField">
<input type="submit" name="mySubmitButton">
</form>

<script language="JavaScript"><!--
function submitForm() {
    document.myForm.mySubmitButton.click();
}
//--></script>

<a href="#" onClick="document.myForm.myHiddenField.value='Hello World';this.href='javascript:submitForm()'">Hello World</a>

The following was submitted by E. v.d. Beemt

It is also possible to submit the form without showing/using the submit-button.

All you have to to is change the code:

document.myForm.mySubmitButton.click();

with :

document.myForm.submit();

and erase the submit-button:

<script language="JavaScript" type="text/javascript"><!--
function submitForm(fieldValue) {
  document.myForm.myHiddenField.value=fieldValue;
  document.myForm.submit();
}
//--></script>

<form name="myForm">
  <input type=hidden name="myHiddenField">
  <a href="javascript:submitForm('Hello World')">Hello World</a>
</form>

Feedback on 'Q924 How can I pass a hidden value to a form and submit that form when a text link is clicked?'

©2018 Martin Webb