Cannot programmatically submit form [duplicate] - javascript

This question already has answers here:
"Submit is not a function" error in JavaScript
(19 answers)
Closed 8 years ago.
Cannot get my form to submit programmatically, despite trying several ways. Tried pure JS, also tried jQuery. No success.
I have this form tag :
<form action="https://docs.google.com/forms/d/13zex8ZsEsnZz3A8uB4jU4oDb5wZfaqqq2Pq2CGlIe6M/formResponse" method="POST" id="ss-form" target="_self" onsubmit="" name="eForm">
<!--My Form Stuff-->
<input type="submit" name="submit" value="Submit" id="ss-submit">
</form>
Here is what i've tried :
/*jQuery*/
$('#ss-form').submit();
/*Javascript*/
document.getElementById('ss-form').submit();
document.eForm.submit();
None of them work. Not sure why, but I am assuming it has something to do with me trying to submit a google form. If I physically click the submit everything works fine.
Any and all help is greatly apprecaiated.

The problem is that you have a field (HTMLInputElement) with name submit in the form. That's why document.getElementById('ss-form').submit is not a function but an object.
So, you get the following error:
TypeError: object is not a function
The solution is to remove that element. We should be careful to verify if browser thinks it's an element and not a function:
if (typeof document.getElementById('ss-form').submit === "object") {
document.getElementById('ss-form').submit.remove();
}
document.getElementById('ss-form').submit();

Related

form onsubmit delaying window.open not working [duplicate]

This question already has answers here:
Prevent form redirect OR refresh on submit?
(7 answers)
Closed 2 years ago.
I have been trying to figure this out for past few hours, I have form and when users will submit it,
new window popup will occur, however I want it delayed slightly, setting setTimeout did not work and I have no idea why.
example:
<form method="post" target="print_popup" action="https://example.com" onsubmit="window.open('about:blank','print_popup','width=1000,height=800');">
<input type="hidden" name="param" value="foobar">
<input id="1" type="submit" value="Submit request">
Think you will need to set the target attribute of the form to _blank to allow for opening a new context:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form
I would also check chrome/your choice of browser isn't blocking your popup

PHP: How to return to same spot on page after clicking Submit? [duplicate]

This question already has answers here:
Is it safe to use anchor to submit form?
(3 answers)
Closed 2 years ago.
I'm making a web page with 20 different questions on the index page. The user clicks "Submit" after every question.
<form action="./index.php" method="post" id="element">
The information is then posted and sent to the database. Of course this makes the index page reload and display at the very top of the page. This makes for a lot of scrolling.
Is there a way to make it so the page reloads and scrolls back down to the place where it left off?
The answer was found here: https://stackoverflow.com/a/7983093/4101210
To use an anchor to submit a form would require the use of JavaScript to hook up the events. It's not safe in that if a user has JavaScript disabled, you won't be able to submit the form. For example:
<form id="form1" action="" method="post">
Submit!
</form>
If you'd like you can use a <button>:
<button type="submit">Submit!</button>
Or stick with what we all know:
<input type="submit" value="Submit!" />
You can style all three of them, but the latter two don't require JavaScript. You probably just need to change some CSS somewhere if you're having border issues.
The code that answered my question was by joshua bissot. He showed how to put the token in the action and name the anchor to make this work.
https://stackoverflow.com/a/25918771/12140988
<!-- add the anchor token at the end of your action statement -->
<form method='post' action='this_page.php?put_peram=token#anchor_name'>
<input type='submit' value='click here'>
<!-- put the anchor right above where you want the page to index -->
<a name="anchor_name></a>

Submit form using <a> tag after confirm [duplicate]

This question already has answers here:
submit event does not fire if submit initiated programmatically
(2 answers)
Closed 5 years ago.
I am trying to submit a form through a tag. I have tried triggering document.myform.submit(), this.form.submit(), parentNode.submit() etc. but none of this is working! Using a submit button or remove confirm() the code works fine. But I want to use both of them. Need some help.
<form method="post" onsubmit="return confirmm('Delete this record?');">
<a href="" class="deleteThisRecord" type="submit" onclick="$(this).closest('form').submit();" name="delete">
Delete This Record
</a>
<input type="hidden" name="id" value="<{$listData[I]['id']}>">
</form>
function confirmm($confirmText = 'Delete?') {
var dicision = confirm($confirmText);
if (dicision) {
return true;
} else {
return false;
}
return false;
}
Give an id attribute to a form, and call submite to this id reference document, getById('yourIdName').submit();

html Form not recognized in my jsp page

I have a JSP page which is included in the main page..Within the JSP page, I have given a HTMLform which I want to submit() once the user clicks it using Jquery?
<form id="orderBean1" name="myForm" action="/Auto/Item" method="post">
<input id="filename" name="filename" value="" />
</form>
First,
Suprisingly, this form is not recognized within the page..
When I give $('#orderBean1') in my console it does not give the form object whereas $('#filename') gives me the filename input element.
Second ,
As the form is not recognized it does not get submitted...
$("#vehreport").click(function(e) {
e.preventDefault();(I have given this stmt even after the submit() and still not working...
$("#orderBean1").submit();
alert("formsubmnittted");
})
Question -
Why doesn't the form element is recognized in my page?
I set up a JSbin here.
As you can see, #orderbean1 is recognized, and submits.
The error is likely elsewhere is your JS or markup, though if I'm misunderstanding the question please clarify

Why won't my js form submit work? [duplicate]

This question already has answers here:
Property 'submit' of object #<HTMLFormElement> is not a function
(3 answers)
Closed 9 years ago.
I have an iframe and a form. I want to submit the form into the iframe. This works, but the JS won't submit the form. I want the form to submit on page load or just when the script is rendered by the browser. I have already tried about 10 different JavaScript variants and successfully submitted the form with a button. Any thoughts?
<iframe src="http://domain.com" name="i0"></iframe>
<form action="http://domain.com/" target="i0" id="f0" method="POST">
<input type="hidden" name="secret" value="4cda562cd5dafa1882c9f18dc0dc5dba">
<input type="hidden" name="id" value="39">
</form>
<script type='text/javascript'>
document.getElementById('f0').submit();
</script>
<input type="submit" name="submit">
this is what's causing your issue, change its name to something else. because now this
document.getElementById('f0').submit();
is trying to access that input, and giving the error:
TypeError: document.getElementById(...).submit is not a function
You should have posted all your form code here, we could have found it faster :)
Maybe it is because your iframe hasn't fully loaded yet, so you need to wait for it:
<script type='text/javascript'>
document.getElementsByName('iframe')[0].onload = function(){
document.getElementById('f0').submit();
}
</script>
I see, you cant' use name="submit" here because you are overwritting FORM submit method, change it, e.g:
<input type="submit" name="bsubmit">

Categories

Resources