943,910 Members | Top Members by Rank

Ad:
Dec 15th, 2005
0

Javascript fails in Firefox

Expand Post »
I can run the following javascript code succefully in IE browser:

<script language="JavaScript" type="text/JavaScript">
document.formname.submit();
</script>

this javascript automatically submit the form when running the page.

However I have problem in Firefox browser, it's stuck at this code (cannot submit form).

Any idea what I need to modify so it works both on IE and Firefox? thanks.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
michael123 is offline Offline
93 posts
since Jun 2005
Jan 4th, 2006
0

Re: Javascript fails in Firefox

IE can use the forms name element to identify the form. I hope that the same is not true for firefox. but I think in firefox and IE you can use the forms ID attribute ( the form should still have a name!! ).

I prefer to use this technique:

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. var formToSend = document.getElementById("formId");
  2. formToSend.submit();

This technique should work on all browsers that have JavaScript enabled.
Reputation Points: 20
Solved Threads: 5
Junior Poster
alpha_foobar is offline Offline
182 posts
since May 2005
Jun 18th, 2008
0

Re: Javascript fails in Firefox

I know this is over a year old, but I'd like to update the response for any googlers. The following will work in all major browsers:

document.formname.submit(); where "formname" is the same as the form's "name" attribute.

OR

document.getElementById('formid').submit(); where "formid" is the same as the form's "id" attribute.

Again, either code will work, and it's preferable to keep your code clean by removing unnecessary code/lines (like where the previous poster created a variable and then submitted that variable).
Reputation Points: 10
Solved Threads: 1
Newbie Poster
joequincy is offline Offline
5 posts
since Mar 2007
Jun 19th, 2008
0

Re: Javascript fails in Firefox

Hi,

I think alpha_foobar has written code in more cleaner way than joequincy. Its always better to declare variable and gave them good name so that it can understand by others.

formToSend.submit(); is more meaningfull than documnt.getElementById(formid).submit();

Always write code so that anyone can understand it easily.
Reputation Points: 83
Solved Threads: 61
Posting Pro in Training
Luckychap is offline Offline
442 posts
since Aug 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: Code to populate pages with multiple artists?
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: template management of the website





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC