Javascript code that works in Firefox but not in IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • knkk
    New Member
    • Jun 2007
    • 49

    Javascript code that works in Firefox but not in IE

    I have a link called "Save" on a page of mine, which, when clicked on (the url is typically like this)
    Code:
    javascript:savesubmit('form31','results31','1','movies','178')
    , calls a javascript function called "savesubmit ", which in turn calls a script using AJAX (the script URL is http://www.mysite.com/section/myspace/save.php).

    This is the JavaScript function savesubmit:

    Code:
    function savesubmit(formname, loc, noofvenues, which, mapid)
    {
    	var f = document.forms[formname];
                 alert(f);//this alert was to test if the form name was coming in properly
    	var params = "";
    	for (i=0;i < (f.elements.length);i++) {
    		params = params + f.elements[i].name +'='+ encodeURI(f.elements[i].value) + '&'; 
    	}
    
    	shows = loc;
    	xmlHttp=GetXmlHttpObject();
    	
    	if (xmlHttp==null)
    	{
    		alert ("Browser does not support HTTP Request");
    		return;
    	}
    	var url = 'http://www.mysite.com/section/myspace/save.php/'+which+'/'+f.eventid.value+'/1/'+mapid+'/'+noofvenues
    	var eventid = f.eventid.value;
    	url = url + "?" + params;
    	var update_loc = eventid + 'save';
    	var update_form = eventid;
    	xmlHttp.onreadystatechange=stateChangedALL;
    	xmlHttp.open("GET",url,true);
    	xmlHttp.send(null);
    	updatesave(update_form, update_loc, noofvenues, which, mapid);
    }
    The form is in a div tag with id 'form31', and the result will be sent to a div tag with id 'results31'.

    The problem is, this thing is working in IE but not in FF. When I click on the Save link, it says "'elements.leng th' is null or not an object". And the alert I put for testing says [object] instead of giving the form name.

    Here is the <td> which has the forms etc.

    Code:
    <TD WIDTH="510" BGCOLOR="#FFFFFF" VALIGN="TOP" STYLE='padding-right: 10'>
    	<A HREF="/profile/movies/31"><SPAN CLASS="Basic_LARGE_BLUE_LINK">Cheeni Kum</SPAN></A> 
    	<BR>
                 <SPAN CLASS="Basic_LARGE_NORMAL">64-year-old Buddhadeb is single and lives with mom. Now, aren't the possibilities endless?</SPAN>
    	<BR>
                 <BR><A HREF='/profile/locations/178'>PVR Cinema (Punjagutta)</A> (13.3 km)
    	<BR><BR>
    	<DIV id="31save" STYLE="float:left">
    		<A HREF="/profile/movies/31/1">Rate</A> • 
    		<A HREF="javascript:savesubmit('form31','results31','1','movies','178')">Save</A> • 
    		<A HREF="/profile/locations/178/4">Map</A>							<DIV STYLE="clear:both;"></DIV>
    	</DIV>
    
    	<FORM NAME="deleteform31" STYLE="margin:0px">
    		<INPUT TYPE="hidden" NAME="eventid" VALUE="31">
    		<INPUT TYPE="hidden" NAME="edittype" VALUE="delete">
    	</FORM>
    	<FORM NAME="form31" STYLE="margin:0px">
    		<INPUT TYPE="hidden" NAME="eventid" VALUE="31">
    		<INPUT TYPE="hidden" NAME="edittype" VALUE="update">
    	</FORM>
    	<DIV STYLE="clear:both"></DIV>
    	<DIV id="results31" ></DIV>
    </TD>
    Can someone kindly help? Thank you for your time!
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    hi ...

    i cannot reproduce the error with your posted code ... it works in a FF 2.0.0.3 and IE 6 here (except of GetXmlHttpObjec t() since you didn't provide it here of course) ... is your 'test-alert' working correct for you? and what does he say? ...

    kind regards

    Comment

    • knkk
      New Member
      • Jun 2007
      • 49

      #3
      Actually, I figured out the error. The <TD> that I gave there is one of a series of rows, each of which has this link for "Save", calling the JavaScript. So there are several rows, and the first variable of the savesubmit function is a form name, with "form" suffixed by a number which is the ID of the record displayed in that row (e. g. "form31"). This form appears in that <TD> itself, so each <TD> has a form named this way.

      There was another row in the same page with the same form name (like "form31"), since that record appeared twice in that page for whatever reason. So when I clicked on that "Save" link, the JS function did not know which form to access. IE just kept saying what I said it did, while FF did not give up - it performed the action on the first form with that name that it encountered.

      I wasted your time with a screw-up from my side, I guess :). Thank you again for your time. Cheers!

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        no problem ... glad to hear you got it working ;) ... come back anytime when you have more questions ...

        kind regards

        Comment

        Working...