FF vs IE dhtml/javascript/forms issue

Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Reply

Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

FF vs IE dhtml/javascript/forms issue

 
0
  #1
Mar 14th, 2008
Hello,

I am having an issue with a page that works fine in IE and not FF. Bascially it is a <div> loaded with a basic coldfusion input form that posts back to parent of the div page. Problem I am having is a validation routine in javascript seems to not to want to find my form or it's elements when I fetch the page into the div (innerhtml via xmlhttprequest) , it works perfectly when I run the page by itself even in FF. The form has a unique id and name, getElementByID only works in FF when I run the page stand-alone, document.forms[formname] also only works stand-alone in FF. I will try to encapsulate the gist of the code here. There are multiple forms on the parent of the div. It's like the form object just disappears from the document. I thought it might be forms within tables, or some malformed html that FF just doesn't like, but it looks fine. I think there is just some difference when doing dhtml and scoping of the objects in FF ? Note, the form comes up alright in the parent div, but the javascript functions just can't access the form elements.. everything works fine in IE. btw, the HTMLElement.prototype.innerHTML has been contructor settered/gettered to work with FF like IE, that works fine too in both. another odd thing, is that I do not see the form in the source when viewed by the client browser, is this just a fact of life for dhtml ? Anyway, any ideas on this would be apprecited, short of abandoning dhtml for FF. Oh yeah, and my Reset button will not focus properly in FF..

Javascript giving me the problem:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. function validate_form() {
  2. var has_error=0;
  3. var empty_element=0;
  4. var x=document.forms['add_form'];
  5. // var x=document.forms[0]; work's stand alone (multiple form)on // var x=document.getElementById('add_form'); work's stand alone only
  6. var div_handle = document.getElementById("form_message");
  7. div_handle.innerHTML = "";
  8. var error_message = "";
  9.  
  10. // here is x.length is undefined when dhtml'd in to the parents div ?? :(
  11. for (var i=0;i<x.length;i++)
  12. {
  13. empty_element=0;
  14. blah = x.elements[i].value;
  15. // alert( x.elements[i].id + ":" + x.elements[i].length +" => Blah:"+ blah + " len:"+ blah.length);
  16. if (blah.length == 0)
  17. { empty_element=1; }
  18. switch (x.elements[i].id)
  19. {
  20. case "f_gr_title":
  21. .. <snip code>
  22. x.elements[i].focus();
  23. }
  24. break;
  25. } // switch
  26. } // for
  27.  
  28. if (has_error) {
  29. div_handle.innerHTML = div_handle.innerHTML+"<br><br>";
  30. }
  31. else {
  32. x.submit(); // submit the form if we have no errors..
  33. }
  34.  
  35. } // validate_form

The form code:
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. <cfform id="add_form" action="index.cfm?act=add" method="POST" name="add_form" enctype="multipart/form-data" onreset="javascript:document.getElementBy('f_gr_title').focus();">
  2.  
  3. <TABLE border="1" cellpadding="1" cellspacing="0" bordercolor="##D2D2D2">
  4. <!---------------- Title ----------------------->
  5. <tr><td align="right">Title</td>
  6. <td><input type="text" size="60" value="" id="f_gr_title" name="f_gr_title" maxlength="60" />
  7. </td></tr>
  8. <!---------------- Description ----------------------->
  9. <tr><td align="right">Description</td>
  10. <td>
  11. <textarea name="f_gr_description" cols="60" id="f_gr_description" height="30">
  12. </textarea>
  13. </td></tr>
  14. <!---------------- Type ----------------------->
  15. <tr><td align="right">Type</td>
  16. <td><cfselect enabled="yes" accesskey="g_tcode" query="qry_type" id="f_gr_type" name="f_gr_type" display="g_tcode" value="g_tvalue"
  17. onChange="javascript:{if (document.getElementById('f_gr_type').value == 'Other') {
  18. var d = document.createElement('div');
  19. var zz = document.createElement('input');
  20. zz.setAttribute('type', 'text');
  21. zz.setAttribute('name', 'f_gr_type_other');
  22. zz.setAttribute('id', 'f_gr_type_other');
  23. zz.setAttribute('size', '60');
  24. d.appendChild(zz);
  25. document.getElementById('otherdiv').appendChild(d);
  26. document.getElementById('f_gr_type_other').focus();
  27. }
  28. else {
  29. // blank out the other_type text if they go to standard type..
  30. var div_handle = document.getElementById('otherdiv');
  31. div_handle.innerHTML = '';
  32. // dynamic_content('otherdiv','');
  33.  
  34. }};">
  35. </cfselect>
  36. <div id="otherdiv">
  37. </div>
  38. </td>
  39. </tr>
  40.  
  41. <!---------------- Status ----------------------->
  42. <tr><td align="right">Status</td>
  43. <td>
  44. <input type="text" value="Pending" name="f_gr_status" id="f_gr_status" disabled="disabled">
  45. </td></tr>
  46. </TABLE>
  47.  
  48. <br>
  49. <div id="form_message" name="form_message"></div>
  50.  
  51. <!---------------- Buttons ----------------------->
  52. <input type="reset" onclick="javascript:document.forms['add_form'].elements['f_gr_title'].focus();"/>
  53. <input type="button" onClick="javascript:cancel_add();" value="Cancel " id="cancel_button">
  54. <input type="button" onClick="javascript:validate_form();" value="Add Request " id="add_button">
  55. </cfform>

Thanks in Advance,
Bob
Reply With Quote Quick reply to this message  
Join Date: Jan 2007
Posts: 3,210
Reputation: MidiMagic has a spectacular aura about MidiMagic has a spectacular aura about 
Solved Threads: 165
MidiMagic's Avatar
MidiMagic MidiMagic is offline Offline
Nearly a Senior Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #2
Mar 15th, 2008
JavaScript is defined to see the webpage's original html, but not any web page elements added by other scripts or programs. IE is the oddball by allowing JS to see the added content.
Last edited by MidiMagic; Mar 15th, 2008 at 3:14 am.
Daylight-saving time uses more gasoline
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #3
Mar 15th, 2008
Thanks !!! That explains a lot, and this is a rather fundamental revelation for me. Wow, I had been developing discrete pages to allow to easy development, and then would incorporate them
into the page via ajaxian ways, while allowing me to jump to opening up pages by themselves if my dhtml ways failed in some way. Never even looked at FF until I realized one of the main users was a mac guy using FF. The way I read this, then I need to incorporate the stand-alone pages into the orginal parent page from the start, and hide/display/manipulate them inline, and do more cross-browser study up front.. Sigh, live and learn. Thank you very much for making this obvious. Not once in my days of googling problems with javascript and this issue was that mentioned or obvious. I have some work ahead of me to fix this fiasco of my own making. If there is any insight on how to bridge this issue, be it javascript libraries that take whole pages and bring them into another for manipulation being already out there, that would outstanding.

Appreciation abounds,
Bob
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #4
Mar 15th, 2008
The essential thing is that your javascript functions are loaded into your main page that the Ajax content is loaded into. You can still call those functions from within the Ajax loaded content.

Here is an example of a highly Ajaxed site that we have in development: http://www.suomedia.com/ghm/


Matti Ressler
Suomedia
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #5
Mar 15th, 2008
My functions are loaded in the main page. They just do not see the dynamic pages loaded via xmlhttp, sigh.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #6
Mar 15th, 2008
You need to identify the element(s) to your function when you call the function rather than relying on your function to identify the element(s), eg.

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. onclick="myFunction('my_element')"


I use it all the time with ajax loaded content - look at the example I posted above, it is rich with javascript. For example, if you look at "Genres", you will see a list with "Show mixes" at the top - click on the ++ to see the list expand - it uses (in multiple):

JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
  1. new Effect.BlindDown('my_element'); // (Scriptaculous)

Individual Albums can be expanded using the single + beside each one.


Matti Ressler
Suomedia
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #7
Mar 15th, 2008
Well, since it the form elements I need to access to validate, I have tried passing the form name or id to it, or even hard coding the form name/id in the function. Nada, zip.. it's as if the form doesn't
exist as an object anymore to js. I will try passing the form as 'this' maybe ? Nice page btw, I would link you to this one, but is it on an intranet of the City of Austin.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 154
Reputation: Suomedia is an unknown quantity at this point 
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #8
Mar 16th, 2008
Yes, I was going to suggest trying 'document.this' (which I also use often - click one of the small speaker icons, then pass your mouse over it again, you will see it re-initialize the music player while the remaining speaker icons do not). However, you may find it necessary to pass all the element id's to the function


Matti Ressler
Suomedia
Reply With Quote Quick reply to this message  
Join Date: Jun 2006
Posts: 7,651
Reputation: ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of ~s.o.s~ has much to be proud of 
Solved Threads: 474
Super Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Failure as a human

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #9
Mar 16th, 2008
> another odd thing, is that I do not see the form in the source when viewed by the client
> browser, is this just a fact of life for dhtml

Yes, because it's the Javascript object XMLHttpRequest provided by the browser at work when fetching content using Ajax. AFAIK, the actual DOM contents at any point in time can be viewed in Firefox using the tool DOM Inspector.

> onClick="javascript:validate_form();"
Don't use Javascript pseudo protocol. It was meant only to be used inside the href attribute of links.

One of the ways to narrow down your problem would be to put a DOCTYPE declaration at the top of your page (without which the browser goes in quirks mode of rendering, in short you have an invalid HTML document) and validate your generated markup at W3C validator.

The next step would be to use the FF error console for spotting errors which don't show up in IE just because IE let's them "slide".
Last edited by ~s.o.s~; Mar 16th, 2008 at 6:03 am.
I don't accept change; I don't deserve to live.

Jo Tujhe Jagaaye, Nindein Teri Udaaye Khwaab Hai Sachcha Wahi.
Nindon Mein Jo Aaye Jise To Bhul Jaaye Khawab Woh Sachcha Nahi.
Khwaab Ko Raag De, Nind Ko Aag De
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 11
Reputation: macslayer is an unknown quantity at this point 
Solved Threads: 1
macslayer macslayer is offline Offline
Newbie Poster

Re: FF vs IE dhtml/javascript/forms issue

 
0
  #10
Mar 17th, 2008
Thanks, guys. So, let me make sure I have a full understanding. Is it correct to state that javascript does not allow access to rendered page elements pulled via ajax, inserted by dhtml into the document, but it is an IE quirk that allowed it ? While I understand that malformed html could weigh heavily in causing normal processing problems, your saying that you think my code would work if I dropped the dhtml innerhtml method and went pure DOM ? Then everything would be tight. In interim, I made code adjustments to see if this was FF, and just stand-alone pages for those users. I would rather it be clickety-click for them too, but would require a bit of retooling to go pure dom in this instance. I will eventually do it, as I see the advantages immediately. Thanks for all your input.

Bob
Reply With Quote Quick reply to this message  
Reply

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



Other Threads in the JavaScript / DHTML / AJAX Forum


Views: 3120 | Replies: 10
Thread Tools Search this Thread



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

©2003 - 2009 DaniWeb® LLC