JavaScript - Code Not Working on Firefox

  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

Code: [ Select ]
function chatSend() {
alert ("CHATSEND1");
if (document.getElementById) {
 alert ("CHATSEND2");
 alert(document.getElementById('message').value); <<<<<Not Working!
 var message = document.getElementById('message').value; <<<<<Not Working!
 alert ("CHATSEND3");
 document.getElementById('message').value = "";
} else if (document.all) {
 var message = document.all['message'].value;
 document.all['message'].value = "";
} else if (document.layers) {
 var message = document.layers['message'].value;
 document.layers['message'].value = "";
}
myurl = "php/in.php?u="+user+"&p="+pass+"&a="+area+"&m="+message+"&t="+Date.parse(new Date());
alert(myurl);
httpc = getHTTPObject();
httpc.open("GET", myurl, true);
httpc.send(null);
chatGrab();
}
  1. function chatSend() {
  2. alert ("CHATSEND1");
  3. if (document.getElementById) {
  4.  alert ("CHATSEND2");
  5.  alert(document.getElementById('message').value); <<<<<Not Working!
  6.  var message = document.getElementById('message').value; <<<<<Not Working!
  7.  alert ("CHATSEND3");
  8.  document.getElementById('message').value = "";
  9. } else if (document.all) {
  10.  var message = document.all['message'].value;
  11.  document.all['message'].value = "";
  12. } else if (document.layers) {
  13.  var message = document.layers['message'].value;
  14.  document.layers['message'].value = "";
  15. }
  16. myurl = "php/in.php?u="+user+"&p="+pass+"&a="+area+"&m="+message+"&t="+Date.parse(new Date());
  17. alert(myurl);
  18. httpc = getHTTPObject();
  19. httpc.open("GET", myurl, true);
  20. httpc.send(null);
  21. chatGrab();
  22. }


Alright I've got a function that's working fine on Internet Explorer but when I try to run it on Firefox it doesn't work.

I was using alerts to diagnose what was going on. The first two alerts (CHATSEND1 and CHATSEND2) appear but after that any remaining code doesn't do anything - which leads me to believe that I cannot retrieve document.getElementById('message').value on Firefox.

Does anyone know what I can do to fix this code so it works on both IE and Firefox?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

what is the html code you are using?
  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

I figured it out. I didn't specify an id tag. I only specified a name. This works on IE for some reason...

Anyways it's fixed now. Thanks for your help.
  • cjxxi
  • Expert
  • Expert
  • cjxxi
  • Posts: 565
  • Loc: Fort Worth, TX

Post 3+ Months Ago

Azoundria wrote:
I figured it out. I didn't specify an id tag. I only specified a name. This works on IE for some reason...

Anyways it's fixed now. Thanks for your help.




I thought so.


glad you fixed
  • Azoundria
  • Professor
  • Professor
  • User avatar
  • Posts: 907
  • Loc: Calgary, Alberta, Canada

Post 3+ Months Ago

This always happens to me! I spend hours and hours trying to fix something and in desperation I post here. Then suddenly the answer comes to me. It's really annoying.
  • pravin3832
  • Born
  • Born
  • pravin3832
  • Posts: 1

Post 3+ Months Ago

Hi Azoundria

I was having the similar problem in firefox and safari and it got solved because of the information in this thread.

Now, i'm having a similar problem while trying to call a servlet from the javascript. It works fine in IE, but not in firefox or safari. I've put some alert() messages before and after the servlet call, and the one after the call does not pop up in firefox or safari..
I'll paste the code here.. any help is appreciated..

Code: [ Select ]
 
function getXmlHttpRequestObject() {
    if (window.XMLHttpRequest) {
        return new XMLHttpRequest();
    } else if(window.ActiveXObject) {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } else {
        alert("Not supported");
    }
}
 
var searchReq = getXmlHttpRequestObject();
 
function searchSuggest(keyEvent) {
alert('i was called,' + searchReq.readyState);
    if (searchReq.readyState == 4 || searchReq.readyState == 0) {
        var keyCode = escape(keyEvent.keyCode);
                var textBoxValue = escape(document.getElementById('textField').value);
                if (keyCode == 17 || keyCode == 16) {
                    //searchReq.send(null);
                }
                else {
                alert(keyCode + ", " + textBoxValue);
 
                alert('II');
 
                    searchReq.open("GET", 'http://rstintel26.us.oracle.com:8888/SuggestiveSearchApplication-GetSuggestions-context-root/findsuitablesuggestions?pressedKeyCode=' + keyCode + '&presentTextFieldValue=' + textBoxValue, true);
 
                alert('III');
                    searchReq.onreadystatechange = handleSearchSuggest;
                alert('IV');
                    searchReq.send(null);
                }
    }
        else {
            alert('not ready yet');
        }
}
 
  1.  
  2. function getXmlHttpRequestObject() {
  3.     if (window.XMLHttpRequest) {
  4.         return new XMLHttpRequest();
  5.     } else if(window.ActiveXObject) {
  6.         return new ActiveXObject("Microsoft.XMLHTTP");
  7.     } else {
  8.         alert("Not supported");
  9.     }
  10. }
  11.  
  12. var searchReq = getXmlHttpRequestObject();
  13.  
  14. function searchSuggest(keyEvent) {
  15. alert('i was called,' + searchReq.readyState);
  16.     if (searchReq.readyState == 4 || searchReq.readyState == 0) {
  17.         var keyCode = escape(keyEvent.keyCode);
  18.                 var textBoxValue = escape(document.getElementById('textField').value);
  19.                 if (keyCode == 17 || keyCode == 16) {
  20.                     //searchReq.send(null);
  21.                 }
  22.                 else {
  23.                 alert(keyCode + ", " + textBoxValue);
  24.  
  25.                 alert('II');
  26.  
  27.                     searchReq.open("GET", 'http://rstintel26.us.oracle.com:8888/SuggestiveSearchApplication-GetSuggestions-context-root/findsuitablesuggestions?pressedKeyCode=' + keyCode + '&presentTextFieldValue=' + textBoxValue, true);
  28.  
  29.                 alert('III');
  30.                     searchReq.onreadystatechange = handleSearchSuggest;
  31.                 alert('IV');
  32.                     searchReq.send(null);
  33.                 }
  34.     }
  35.         else {
  36.             alert('not ready yet');
  37.         }
  38. }
  39.  


Here, when i run the program, I can see upto 'II' popping up while using firefox/safari.. but in IE, all the pop-ups come.

Thanks
Pravin
  • gonzo_rulz
  • Born
  • Born
  • gonzo_rulz
  • Posts: 2

Post 3+ Months Ago

I'm having problems with the original thread topic.

here's a small snippet

Code: [ Select ]
packPrice = parseFloat(document.getElementById('TourPrice').innerHTML.substring(1,4))


in IE that is fine an returns the figure eg. "133"

in firefox the same code returns "b><"

please help

Edit: I have made some changes to my HTML code and used span instead of div. and it seems to work in FireFox that way, but it does change my allignment. here is more code

Code: [ Select ]
<b><font size="2" face="Verdana"><div id="TourPriceCaption" align="right">Package Subtotal:</div></font>
                    <font size="3" face="Verdana"><div id="TourPrice" align="right">$0.00</div></font></b>
                    <b><font size="2" face="Verdana"><div id="AccomPriceCaption" align="right">Accommodation Upgrade:</div></font>
                    <font size="3" face="Verdana"><div id="AccomPrice" align="right">$0.00</div></font></b>
                    <b><font face="Verdana"><div id="TotalPriceCaption" align="right">Total Price:</div></font>
                    <font size="5" face="Verdana"><div id="TotalPrice" align="right">$0.00</div></font></b>
                    </td>
  1. <b><font size="2" face="Verdana"><div id="TourPriceCaption" align="right">Package Subtotal:</div></font>
  2.                     <font size="3" face="Verdana"><div id="TourPrice" align="right">$0.00</div></font></b>
  3.                     <b><font size="2" face="Verdana"><div id="AccomPriceCaption" align="right">Accommodation Upgrade:</div></font>
  4.                     <font size="3" face="Verdana"><div id="AccomPrice" align="right">$0.00</div></font></b>
  5.                     <b><font face="Verdana"><div id="TotalPriceCaption" align="right">Total Price:</div></font>
  6.                     <font size="5" face="Verdana"><div id="TotalPrice" align="right">$0.00</div></font></b>
  7.                     </td>


the code from my original post returns NaN in Firefox when i have div tags. Suggestions?
  • val_atharv
  • Born
  • Born
  • val_atharv
  • Posts: 1

Post 3+ Months Ago

Hi,

This looks great post, I am am having the same issue javascript does not work in Firefox, it works perfectly fine in IE.

I am tring to run a sample got while searching, please suggest... what should I change.

HTML
----
Code: [ Select ]
<h:form id="form1" name="form1" >
<select name="sport" id="sport" onChange="set_player();">
    <option value="" selected="selected">Select Item</option>
    <option value="tennis" id="tennis">Tennis</option>
    <option value="cricket" id="cricket">Cricket</option>
</select> Select Player
<select name="player" id="player">
    <option value="" selected="selected"></option>
</select>
</h:form>
  1. <h:form id="form1" name="form1" >
  2. <select name="sport" id="sport" onChange="set_player();">
  3.     <option value="" selected="selected">Select Item</option>
  4.     <option value="tennis" id="tennis">Tennis</option>
  5.     <option value="cricket" id="cricket">Cricket</option>
  6. </select> Select Player
  7. <select name="player" id="player">
  8.     <option value="" selected="selected"></option>
  9. </select>
  10. </h:form>


JavaScript:
----------
Code: [ Select ]
<script type="text/javascript">
//<![CDATA[
var tennisplayers = new Array("Safin","Andre Agassi","Pete Sampras","Anna Kournik","Martina Hingis");
var cricketplayers = new Array("Sachin Tendulkar","Steve Waugh","Brian Lara","Sir Bradman");
function set_player(){
var select_sport= document.form1.sport;
var select_player= document.form1.player;

var selected_sport= select_sport.options[select_sport.selectedIndex].value;

select_player.options.length=0;
if (selected_sport == "tennis"){
    for(var i=0; i < tennisplayers.length; i++)
select_player.options[select_player.options.length] = new Option(tennisplayers[i],tennisplayers[i]);
}
if (selected_sport == "cricket"){
    for(var i=0; i < cricketplayers.length; i++)
select_player.options[select_player.options.length] = new Option(cricketplayers[i],cricketplayers[i]);
}
}//]]>
</script>
  1. <script type="text/javascript">
  2. //<![CDATA[
  3. var tennisplayers = new Array("Safin","Andre Agassi","Pete Sampras","Anna Kournik","Martina Hingis");
  4. var cricketplayers = new Array("Sachin Tendulkar","Steve Waugh","Brian Lara","Sir Bradman");
  5. function set_player(){
  6. var select_sport= document.form1.sport;
  7. var select_player= document.form1.player;
  8. var selected_sport= select_sport.options[select_sport.selectedIndex].value;
  9. select_player.options.length=0;
  10. if (selected_sport == "tennis"){
  11.     for(var i=0; i < tennisplayers.length; i++)
  12. select_player.options[select_player.options.length] = new Option(tennisplayers[i],tennisplayers[i]);
  13. }
  14. if (selected_sport == "cricket"){
  15.     for(var i=0; i < cricketplayers.length; i++)
  16. select_player.options[select_player.options.length] = new Option(cricketplayers[i],cricketplayers[i]);
  17. }
  18. }//]]>
  19. </script>
  • gonzo_rulz
  • Born
  • Born
  • gonzo_rulz
  • Posts: 2

Post 3+ Months Ago

I've got mine working in FireFox now, but I had to change my HTML side of things. Instead of using <DIV id .... I changed it a table format and used <tr id ...

I realize that it doesn't answer why Firefox didn't work before, but at least it's working now...

Post Information

  • Total Posts in this topic: 9 posts
  • Users browsing this forum: No registered users and 93 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.