I need to automatically submit a form using JavaScript or PHP. I tried document.forms.myform.submit() which works in IE but not FF or Chrome. Are there any other ways or things I should try?
I found why document.forms.myform.submit() wasn't working. The name of my button was "submit" which was throwing the javascript off in only FF and Chrome. I simply changed it to submit2 which worked:
bank5
Member
92 Points
296 Posts
How to submit automatically submit a form using javascript?
Jan 06, 2010 09:16 PM|LINK
I need to automatically submit a form using JavaScript or PHP. I tried document.forms.myform.submit() which works in IE but not FF or Chrome. Are there any other ways or things I should try?
Bobby-Z
Contributor
2838 Points
1120 Posts
Re: How to submit automatically submit a form using javascript?
Jan 06, 2010 09:21 PM|LINK
Do you have javascript enabled in these other browsers?
Currently Learning: ASP, SQL, CSS, JavaScript, AJAX, XML, XSLT, C# So please be patient with me! Thanks
malcolms
All-Star
18687 Points
3124 Posts
MVP
Re: How to submit automatically submit a form using javascript?
Jan 06, 2010 10:15 PM|LINK
You can use jQuery's trigger function to trigger an event like submitting a form.
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: How to submit automatically submit a form using javascript?
Jan 06, 2010 10:25 PM|LINK
Try:
<script type=text/javascript>
<!--
function autoSubmit()
{
<%= ClientScript.GetPostBackEventReference(this, "") %>;
}
// -->
</script>
Or if using VB:
<%= ClientScript.GetPostBackEventReference(Me, "") %>;
NC...
bank5
Member
92 Points
296 Posts
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 02:40 PM|LINK
Yes, Javascript is enabled in the browsers.
bank5
Member
92 Points
296 Posts
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 02:41 PM|LINK
The site is hosting on a linux box so unfortunately I can't use .NET
NC01
All-Star
82577 Points
15430 Posts
MVP
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 02:46 PM|LINK
I hate to tell you this, but this happens to be an ASP.NET forum.
NC...
bank5
Member
92 Points
296 Posts
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 03:40 PM|LINK
I found why document.forms.myform.submit() wasn't working. The name of my button was "submit" which was throwing the javascript off in only FF and Chrome. I simply changed it to submit2 which worked:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"><input type="submit" name="submit2" value="Submit1"></div><input type="submit" name="submit2" value="Submit">
bank5
Member
92 Points
296 Posts
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 03:41 PM|LINK
Thanks! This worked too (Assuming the name of button is anything other than "submit") and was easy to implement.
malcolms
All-Star
18687 Points
3124 Posts
MVP
Re: How to submit automatically submit a form using javascript?
Jan 08, 2010 08:30 PM|LINK
Excellent. I'm glad it worked. I'm a big believer in jQuery and its ease of use.