471,857 Members | 1,876 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,857 software developers and data experts.

Javascript code that works in Firefox but not in IE

49
I have a link called "Save" on a page of mine, which, when clicked on (the url is typically like this)
Expand|Select|Wrap|Line Numbers
  1. 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:

Expand|Select|Wrap|Line Numbers
  1. function savesubmit(formname, loc, noofvenues, which, mapid)
  2. {
  3.     var f = document.forms[formname];
  4.              alert(f);//this alert was to test if the form name was coming in properly
  5.     var params = "";
  6.     for (i=0;i < (f.elements.length);i++) {
  7.         params = params + f.elements[i].name +'='+ encodeURI(f.elements[i].value) + '&'; 
  8.     }
  9.  
  10.     shows = loc;
  11.     xmlHttp=GetXmlHttpObject();
  12.  
  13.     if (xmlHttp==null)
  14.     {
  15.         alert ("Browser does not support HTTP Request");
  16.         return;
  17.     }
  18.     var url = 'http://www.mysite.com/section/myspace/save.php/'+which+'/'+f.eventid.value+'/1/'+mapid+'/'+noofvenues
  19.     var eventid = f.eventid.value;
  20.     url = url + "?" + params;
  21.     var update_loc = eventid + 'save';
  22.     var update_form = eventid;
  23.     xmlHttp.onreadystatechange=stateChangedALL;
  24.     xmlHttp.open("GET",url,true);
  25.     xmlHttp.send(null);
  26.     updatesave(update_form, update_loc, noofvenues, which, mapid);
  27. }
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.length' 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.

Expand|Select|Wrap|Line Numbers
  1. <TD WIDTH="510" BGCOLOR="#FFFFFF" VALIGN="TOP" STYLE='padding-right: 10'>
  2.     <A HREF="/profile/movies/31"><SPAN CLASS="Basic_LARGE_BLUE_LINK">Cheeni Kum</SPAN></A> 
  3.     <BR>
  4.              <SPAN CLASS="Basic_LARGE_NORMAL">64-year-old Buddhadeb is single and lives with mom. Now, aren't the possibilities endless?</SPAN>
  5.     <BR>
  6.              <BR><A HREF='/profile/locations/178'>PVR Cinema (Punjagutta)</A> (13.3 km)
  7.     <BR><BR>
  8.     <DIV id="31save" STYLE="float:left">
  9.         <A HREF="/profile/movies/31/1">Rate</A>  
  10.         <A HREF="javascript:savesubmit('form31','results31','1','movies','178')">Save</A>  
  11.         <A HREF="/profile/locations/178/4">Map</A>                            <DIV STYLE="clear:both;"></DIV>
  12.     </DIV>
  13.  
  14.     <FORM NAME="deleteform31" STYLE="margin:0px">
  15.         <INPUT TYPE="hidden" NAME="eventid" VALUE="31">
  16.         <INPUT TYPE="hidden" NAME="edittype" VALUE="delete">
  17.     </FORM>
  18.     <FORM NAME="form31" STYLE="margin:0px">
  19.         <INPUT TYPE="hidden" NAME="eventid" VALUE="31">
  20.         <INPUT TYPE="hidden" NAME="edittype" VALUE="update">
  21.     </FORM>
  22.     <DIV STYLE="clear:both"></DIV>
  23.     <DIV id="results31" ></DIV>
  24. </TD>
  25.  
Can someone kindly help? Thank you for your time!
Jul 25 '07 #1
3 1265
gits
5,390 Expert Mod 4TB
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 GetXmlHttpObject() since you didn't provide it here of course) ... is your 'test-alert' working correct for you? and what does he say? ...

kind regards
Jul 25 '07 #2
knkk
49
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!
Jul 26 '07 #3
gits
5,390 Expert Mod 4TB
no problem ... glad to hear you got it working ;) ... come back anytime when you have more questions ...

kind regards
Jul 26 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

12 posts views Thread by Howard Kaikow | last post: by
5 posts views Thread by LRW | last post: by
8 posts views Thread by chrisdude911 | last post: by
4 posts views Thread by lmarceglia | last post: by
11 posts views Thread by minnesotti | last post: by
11 posts views Thread by Joey | last post: by
8 posts views Thread by Matt Kruse | last post: by
16 posts views Thread by Eric | last post: by
NeoPa
reply views Thread by NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.