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>