Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Cross browser javascript problem

Javascript function works in firefox but not in IE

5:40 am on Apr 16, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 16, 2009
votes: 0

Hi all,
I have recently joined the web master's community and i'm a beginner to javascripts.
I have a javascript function which works fine firefox but not in IE, an error "object doesn't support this property or method" occurs when the modify functionality is used. I would appreciate any help on this. I'm attaching the script function and the jsp code here.

JSP code:
<div class="ico">
<a href="#" title="modify" onclick="submitForm()"> <img src="../images/ico_natiz.gif" alt="modifica" border="0"> </a>

Javascript code:
function submitForm(nameId){
else{ document.getElementById("submitForm").onsubmit(); document.getElementById("submitForm").submit();

Thanks for the help in advance:)

6:52 am on Apr 16, 2009 (gmt 0)

Preferred Member

10+ Year Member

joined:Apr 14, 2003
votes: 0

Is the forms id nameId? if it is It should be
<a href="#" title="modify" onclick="submitForm('nameId')">

The function "submitForm(nameId)" requires something to be passed to it.

Also are you checking if a certain id exists?

Then instead of


it should be something like

if(document.getElementById(nameId) != null)

10:41 am on Apr 16, 2009 (gmt 0)

New User

5+ Year Member

joined:Apr 16, 2009
votes: 0

I have tried both suggestions made by you, but when only 'nameId' is passed to the script function the modify option is not working in both the browsers:(

When the 2nd suggestion for checking the id "if(document.getElementById(nameId) != null)" is implemented, it works in firefox but not in IE.

Is there any other changes that can be done to get it working in IE too? I have been struggling to get ride of this bug for over a week now.

1:22 pm on Apr 16, 2009 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Oct 17, 2005
votes: 24

Welcome to WebmasterWorld! Using JavaScript to submit your form will break your functionality for people with JavaScript disabled, so you might want to reconsider your approach. That is... use a real button instead of a link.

As for you function, it's attempting to take a string input and get the form element with that ID. If no string was input, it defaults to getting a form with the id of "submitForm". You can reduce the number of calls to document.getElementById to make it more efficient. Also, the call to the form's onsubmit() handler will cause an error if that handler has not been set. So that could be rewritten:

function submitForm(formId) {
// Get the form element using the passed in formId
// or the default 'submitForm' if no id passed in.
var frm = document.getElementById(formId ? formId: 'submitForm');
// Perform a check to make sure the form exists
if (frm != null) {
// Perform a check to make sure the form's
// onsubmit event handler was set
if (frm.onsubmit != null) {

Note, this is very much dependent on event 'handlers' (vs. event 'listeners').