Javascript fails in Firefox

Please support our JavaScript / DHTML / AJAX advertiser: 50% Off 6 Months Web Hosting from 1&1. The World's #1 Host!
Reply

Join Date: Jun 2005
Posts: 92
Reputation: michael123 is an unknown quantity at this point 
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Javascript fails in Firefox

 
0
  #1
Dec 15th, 2005
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.
Reply With Quote Quick reply to this message  
Join Date: May 2005
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Javascript fails in Firefox

 
0
  #2
Jan 4th, 2006
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.
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 5
Reputation: joequincy is an unknown quantity at this point 
Solved Threads: 1
joequincy's Avatar
joequincy joequincy is offline Offline
Newbie Poster

Re: Javascript fails in Firefox

 
0
  #3
Jun 18th, 2008
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).
Reply With Quote Quick reply to this message  
Join Date: Aug 2006
Posts: 319
Reputation: Luckychap is on a distinguished road 
Solved Threads: 42
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Posting Whiz

Re: Javascript fails in Firefox

 
0
  #4
Jun 19th, 2008
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.
When you think you have done a lot, then be ready for YOUR downfall.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 14976 | Replies: 3
Thread Tools Search this Thread



Tag cloud for JavaScript / DHTML / AJAX
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2010 DaniWeb® LLC