User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 391,946 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,915 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 8085 | Replies: 3
Reply
Join Date: Jun 2005
Posts: 85
Reputation: michael123 is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 0
michael123 michael123 is offline Offline
Junior Poster in Training

Javascript fails in Firefox

  #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.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Javascript fails in Firefox

  #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:

var formToSend = document.getElementById("formId");
formToSend.submit();

This technique should work on all browsers that have JavaScript enabled.
Reply With Quote  
Join Date: Mar 2007
Posts: 5
Reputation: joequincy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
joequincy's Avatar
joequincy joequincy is offline Offline
Newbie Poster

Re: Javascript fails in Firefox

  #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  
Join Date: Aug 2006
Location: Noida, India
Posts: 152
Reputation: Luckychap is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 16
Luckychap's Avatar
Luckychap Luckychap is offline Offline
Junior Poster

Re: Javascript fails in Firefox

  #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  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

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

All times are GMT -4. The time now is 8:56 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC