|
Q924 How can I pass a hidden value to a form and submit that form when a text link is clicked?
irt.org | Knowledge Base | JavaScript | Form 3.1 | Q924 [ previous next ]
Q924 How can I pass a hidden value to a form and submit that form when a text link is clicked?
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?'
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.