0

I run into absolutely wierd Chrome's behavoir. Below is the code

<form method="post" id="form" accept-charset="UTF-8" action="/lalala">
<input type="submit"  />
<input type="text" name="submit" value="Post this" />
</form>

<script>
    setTimeout(function(){ 
        var forma = document.getElementById("form");
        console.log(forma.submit);
        forma.submit(); 
    },30000);
</script>

it prints to Chrome debug window

<input type="text" name="submit" value="Post this">
Uncaught TypeError: object is not a function

i.e. document.getElementById("form").submit is an input, but not submit callback!!

Is it possible to submit this form keeping input name=submit?

1
  • Try document.forms["form"].submit() Commented Dec 7, 2014 at 8:46

2 Answers 2

1

Is it possible to submit this form keeping input name=submit?

I believe, the answer is NO.

I run into absolutely wierd Chrome's behavoir.

I could find the problem in Firefox too.

The moment you use the key word submit as either the name or id of an element within a form, the form.submit turns in to an object referring the corresponding node instead of the function to submit the form.

Please refer the JSFiddle

<form method="post" id="form" accept-charset="UTF-8" action="/lalala">
    <input type="submit" />
    <input type="text" name="submit" value="Post this" />
</form>


var form = document.getElementById("form");
console.log(typeof form.submit);
Sign up to request clarification or add additional context in comments.

Comments

0

OK I've found the solution:

<input id="submit" type="submit" />
<script>
var button = document.getElementById("submit");
button.click();
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.