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?
Sometimes the problem is caused by old versions of the Javascript files, cached by your browser and can be fixed by clearing the browser cache. You can use the browser console of your browser for debugging. After the Javascript error is fixed, the submit button will automatically be enabled.
When we click on the link, the function submitForm() will get executed. This function will get the element object using DOM getElementById() method by passing the form id to this method, then the form will be submitted by using submit() method. Example: Create a form and submit it using the above approach.
You need a form surrounding the input. Save this answer. Show activity on this post. You have no form tag and even if you did it would need the method="post" attribute.
Approach: To enable or disable the form submit button, we use the below code snippet. $('#enabled'). click(function () { if ($('#submit-button').is(':disabled')) { $('#submit-button').
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.
The problem is that when some element is <input type="submit" name="submit" />
submit() method will not work. The best solution to this situation is to change the name of that submit type input to something else for example button-submit etc.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With