Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
131
rated 0 times [  134] [ 3]  / answers: 1 / hits: 23695  / 14 Years ago, tue, april 27, 2010, 12:00:00

I'm trying to intercept the submission of a form in order to change the value of my keywords label.



I have the following code:



<HTML>
<FORM name=searchForm method=get action=tmp.html >
<input type=text name=keywords />
<input type=button name=submit value=submit onclick=formIntercept();/>
</FORM>
<SCRIPT language=JavaScript>
document.searchForm.keywords.focus();
function formIntercept( ) {
var f = document.forms['searchForm'];
f.keywords.value = 'boo';
f.submit();
};
</SCRIPT>
</HTML>


When I run this in chrome and click the submit button the keywords label changes to boo, but the javascript console says:



 Uncaught TypeError: Property 'submit' of object <#an HtmlFormElement> is not a function.


How can I submit the form with the manipulated keywords?


More From » javascript

 Answers
31

The reason for the error when trying to call form.submit() is that your submit button is called submit. This means that the submit property of your Form object is now a reference to the submit button, overriding the submit method of the form's prototype.



Renaming the submit button would allow you to call the submit() method without error.


[#96956] Saturday, April 24, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cruzjenseny

Total Points: 409
Total Questions: 93
Total Answers: 106

Location: Lithuania
Member since Fri, Sep 4, 2020
4 Years ago
;