jeudi 26 mars 2015

Submit a form from html using Javascript?

I have a form on my html page which has name="submitform" and id="submitform"


I want to submit it using Javascript with the following script on that page:


document.forms("submitform").submit();


My submit button in the form has name="btnSubmit" so it doesn't override the original function.


However, it doesn't work


I get: [Error] TypeError: '[object HTMLCollection]' is not a function (evaluating 'document.forms("submitform")'


What to do?


Thanks!


UPDATE - Full Code



<form action='/post' name='submitform' id="submitform" method='post' class='pure-form'>

<textarea columns="40" rows="4" name='entry[body]' id="statement" placeholder='enter a note here to visualize the words and their connections, you can also use #hashtags and @mentions.'><% if (url) { %><%= urltitle %> <%= url %><% } %></textarea>
<div id="addToContextsLabel">contexts:</div>
<ul id="addToContexts"></ul>
<input type="hidden" id="addedContexts" name="addedContexts">
<input type="hidden" id="context" name="context" value="<%= context %>">
<input type="hidden" id="selectedContexts" name="selectedContexts" value="">
<input type="hidden" name="statementid" value="">
&nbsp;<br>
<input type='submit' id="submitbutton" name="btnSubmit" value="save" class="pure-button pure-button-primary">

</form>


and


document.submitform.submit();


on the page


Aucun commentaire:

Enregistrer un commentaire