Reputation: 6625
I want to set the value of a hidden field and then submit the form with js.
Here's my js:
<script type="text/javascript">
<!--
function doSubmit(formid,fieldid,action) {
var frm=getElementbyId(formid);
var fld=getElementbyId(fieldid);
fld.value = action;
frm.submit();
}
//-->
</script>
Here's my HTML:
<form name="mainform" id="mainform" method="post">
<a href="#" onclick="doSubmit('mainform','dothis','send')">send</a>
<input name="dothis" id="dothis" type="hidden" value="nothing" />
</form>
Result: nothing happens.
When I do <a href="#" onclick="document.mainform.submit()"> ...
the form is submitted (but, of course, the value in dothis
not set.
How to do this?
Upvotes: 0
Views: 1160
Reputation: 531
what is getElementById??? Is it your custom function?? Also I think your form is not submitted. Its just calling the href="#" which is the same link. set the href value to
href="javascript:void(0);"
Upvotes: 1
Reputation: 3355
You have to use
document.getElementById
not
getElementbyId (missing capital B)
Upvotes: 0
Reputation: 3281
Change your Js function :-
<script type="text/javascript">
<!--
function doSubmit(formid, fieldid, action) {
var frm = document.getElementById(formid);
var fld = document.getElementById(fieldid);
fld.value = action;
frm.submit();
}
//-->
</script>
Upvotes: 0