473,396 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Works in IE, but not in FireFox

rrocket
116 100+
This works great in IE, but does not do anything in FireFox... Any ideas of what could be wrong with it? I checked all of the values (in IE through alert statements since nothing shows up in FireFox) and everything is valid.

Thanks...

Expand|Select|Wrap|Line Numbers
  1. function spanHide(spanNum){
  2.     for(startValue = 1;startValue <= 8;startValue++){
  3.         var currentSpan = eval("document.all.spanShip"+spanNum+"_"+startValue);
  4.         var InsureInfo_SpanInsure = eval(document.getElementById("spanInsure" + spanNum + "_1"));
  5.         currentSpan.style.display = "none";
  6.     }
  7.     alert("made it");
  8.     document.getElementById("length_" + spanNum).value = "";
  9.     document.getElementById("width_" + spanNum).value = "";
  10.     document.getElementById("height_" + spanNum).value = "";
  11.     document.getElementById("weight_" + spanNum).value = "";
  12.  
  13.     document.getElementById("spanInsure" + spanNum + "_1").style.display = "none";
  14.         document.getElementById("spanInsure" + spanNum + "_2").style.display = "block";
  15.     //Code added to try and check the Firefox stuff
  16.  
  17.     //End BS Fix
  18.  
  19.     if (document.getElementById("type_" + spanNum).checked == false & document.getElementById("sAcc2_" + spanNum).checked == true)
  20.     {
  21.         document.getElementById("maxInsure_" + spanNum).value = "$500";
  22.         document.getElementById("spanInsure" + spanNum + "_1").style.display = "none";
  23.         document.getElementById("spanInsure" + spanNum + "_2").style.display = "block";
  24.         //alert(document.getElementById("type_" + spanNum).value + "letter");
  25.     }
  26.     else
  27.     {
  28.         document.getElementById("spanInsure" + spanNum + "_1").style.display = "none";
  29.         document.getElementById("spanInsure" + spanNum + "_2").style.display = "none";
  30.     }
  31. }
Aug 24 '07 #1
21 2679
tj111
12
I only had to read two lines of code to see the (potential) problem. "document.all" is only supported by IE, you have to use getElementById (or others) for any other browser. I didn't ready any further, so I don't know if theres more.
Aug 24 '07 #2
rrocket
116 100+
That part is actually working fine in both browsers for whatever reason... It does not seem to like the
Expand|Select|Wrap|Line Numbers
  1. if (document.getElementById("type_" + spanNum).checked == false & document.getElementById("sAcc2_" + spanNum).checked == true)
parts of the code.

When I do
Expand|Select|Wrap|Line Numbers
  1. alert(document.getElementById("type_" + spanNum).checked)
I get the correct values to pop up in IE, but nothing comes up in FireFox.
Aug 24 '07 #3
acoder
16,027 Expert Mod 8TB
When I do
Expand|Select|Wrap|Line Numbers
  1. alert(document.getElementById("type_" + spanNum).checked)
I get the correct values to pop up in IE, but nothing comes up in FireFox.
Have you given the span an id?
Aug 24 '07 #4
rrocket
116 100+
Yes... It is the same as the name. Should not make a difference right?

The spanNum is in that part of code is just a number that is appended to the name. Honestly I do not have a clue why, but it will not let me know the status of the checkbox.
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("type_" + spanNum).checked
should return a true or false depending on what box is checked right? It shows up without an issue in IE.... Here is the code from the checkbox:
Expand|Select|Wrap|Line Numbers
  1. <tr>
  2. <td valign="top" width="33%">
  3. <span class="emphasis2">*</span> 
  4. <b>Type:</b>
  5. </td>
  6.  
  7. <td valign="top">
  8. <input type="radio" name="type_<%=spanLoop%>" id="type_<%=spanLoop%>_1" value="P"<% If curType <> "L" Then response.write "checked" End If %> class="radio" onClick="spanShow(<%=spanLoop%>)"/>
  9. Package &nbsp; &nbsp; 
  10. <input type="radio" name="type_<%=spanLoop%>" id="type_<%=spanLoop%>_0" value="L" class="radio" onClick="spanHide(<%=spanLoop%>)"<% If curType = "L" Then response.write "checked" End If %>/> 
  11. Letter <b>( Less Than 8oz )</b></td>
  12.                 </tr>
Aug 24 '07 #5
acoder
16,027 Expert Mod 8TB
If you look carefully, it is not the same as the name.

The id has a "_0" or a "_1" at the end. IE erroneously accepts the name as an id which obviously then causes problems in other browsers.
Aug 24 '07 #6
Atli
5,058 Expert 4TB
If you look carefully, it is not the same as the name.

The id has a "_0" or a "_1" at the end. IE erroneously accepts the name as an id which obviously then causes problems in other browsers.
It could also be argued that IE intuitively predicts such errors and works around them ;)
Aug 24 '07 #7
drhowarddrfine
7,435 Expert 4TB
It could also be argued that IE intuitively predicts such errors and works around them ;)
Yes, I always want my browser to guess at what I want rather than what I wrote **rollseyes**

The code above is checking for true/false, but the value for "checked" is "checked" and not true or false, but I'm not a js guy.
Aug 25 '07 #8
acoder
16,027 Expert Mod 8TB
It could also be argued that IE intuitively predicts such errors and works around them ;)
That's not prediction; it's just plain wrong. A name is a name and an id is an id. If you want to get elements by name, there's a method for it: document.getElementsByName. Don't misuse document.getElementByID.
Aug 25 '07 #9
acoder
16,027 Expert Mod 8TB
The code above is checking for true/false, but the value for "checked" is "checked" and not true or false, but I'm not a js guy.
That may be the case in HTML, but in Javascript, it's true/false. See link.
Aug 25 '07 #10
Atli
5,058 Expert 4TB
Yes, I always want my browser to guess at what I want rather than what I wrote **rollseyes**.
Yea I must say I totally agree with you there. I was merely demonstrating my awesome "Its not a bug... Its a feature!" ability :)

Would it matter if you actually set the 'checked' value to some value? Like say 'checked=true'.
Aug 25 '07 #11
drhowarddrfine
7,435 Expert 4TB
Don't know what it would do but there is no such value.
Aug 26 '07 #12
acoder
16,027 Expert Mod 8TB
Don't know what it would do but there is no such value.
In HTML, use [HTML]<input type="checkbox" ... checked="checked">[/HTML] and in Javascript,
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("checkID").checked = true;
Aug 26 '07 #13
drhowarddrfine
7,435 Expert 4TB
I understand that but I think he was wondering about this:
Expand|Select|Wrap|Line Numbers
  1.    1.
  2.       <input type="checkbox" ... checked="true">
Checked, in html, has no value of true.
Aug 26 '07 #14
Atli
5,058 Expert 4TB
Actually, after testing this, if the checkbox has the checked parameter in the HTML markup, no matter what value it may or may not have, it will be considered checked. In which case JavaScript will return true.
Aug 27 '07 #15
gits
5,390 Expert Mod 4TB
hi ...

just my two cents about that ... because it's the always misunderstood question about using javascript-obj-properties or setting node-attributes.

in case you set the checked="checked" attrib in html the nodes-cecked property:

Expand|Select|Wrap|Line Numbers
  1. node.checked
equals true. when you set it to false the box will be unchecked and the property is false ... we set it ;) ... but! when you ask for the attrib:

Expand|Select|Wrap|Line Numbers
  1. node.getAttribute('checked') 
equals 'checked' ... so there's a difference between js-properties and the nodes attributes. to uncheck the box with setting the attribute you have to use:

Expand|Select|Wrap|Line Numbers
  1. node.removeAttribute('checked');
  2.  
hope this makes some confusion clear ... and shows, that we always should use ONE method in our code ... either the property-way OR the attribute way ... ok? which one you prefer is up to you ;) but to avoid confusion we shouldn't mix the possibilities ...

and of course ... it's my personal point of view ;)

kind regards

ps: a simple test:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2.     <script>
  3.         function check_checkbox(box) {
  4.             alert('property = ' + box.checked);
  5.             alert('attribute = ' + box.getAttribute('checked'));
  6.         }
  7.     </script>
  8.     <body>
  9.         <input type="checkbox" onclick="check_checkbox(this);" checked="checked"/>
  10.     </body>
  11. </html>
  12.  
Aug 27 '07 #16
hi all!

i just came here for the answer to the first question in this thread.
Can someone help in answering how to make the Document.getElementById method to work in Firefox?
Thanks,
arsthegr8
Jun 3 '08 #17
Atli
5,058 Expert 4TB
Hi. Welcome to Bytes!

The 'document.getElementById()' method does work in Firefox.
It is case-sensitive tho so make sure it is written exactly like I wrote it.
Jun 3 '08 #18
acoder
16,027 Expert Mod 8TB
Welcome to Bytes!

document.getElementById() works in Firefox, you just need to use it in the correct manner. Post your code.

Edit: posted a minute too late...
Jun 3 '08 #19
hi, this javascript works perfect in IExplorer but not in firefox. I get error in line
document.getElementById("supplier_no").value= values_array[0]; .... shows in firefox error console

Error: getElementById returns null. what can be the problem? please help




Expand|Select|Wrap|Line Numbers
  1. var winName;                        //variable for the popup window
  2. var g_return_destination = null ;    //variable to track where the data gets sent back to.
  3.  
  4.  
  5. // Set the value in the original pages text box.
  6. function f_set_home_value( as_Value )
  7. {
  8.     if (document.getElementById(g_return_destination[0]).name == "netbank_supplier_name_info" )
  9.     {
  10.         //clear the old values
  11.         for (selnum = 1; selnum <= 5; selnum++)
  12.         {
  13.             document.getElementById("expense_account"+selnum).value = "";
  14.             document.getElementById("expense_account_name"+selnum).value = "";
  15.             document.getElementById("expense_vat_flag"+selnum).value = "off";
  16.             document.getElementById("expense_vat_flag"+selnum).checked = "";
  17.             document.getElementById("expense_vat_amount"+selnum).value = "";
  18.             document.getElementById("expense_vat_code"+selnum).value = "";
  19.             document.getElementById("expense_period"+selnum).value = "";
  20.             document.getElementById("expense_date"+selnum).value = "";
  21.             if (selnum!=1) {//these are sometimes defaulted in, and in any case you will always have line1
  22.                 document.getElementById("expense_more_dept"+selnum).value = "";
  23.                 document.getElementById("expense_more_prj"+selnum).value = "";
  24.                 document.getElementById("expense_more_subj"+selnum).value = "";
  25.             }
  26.             document.getElementById("expense_amount"+selnum).value = "";
  27.         }
  28.         var values_array = as_Value[0].split("!");
  29.         document.getElementById("supplier_no").value= values_array[0];
  30.         document.getElementById("supplier_bankAccount_no").value= values_array[1];
  31.         str = values_array[2] ;
  32.         str = str.split(";sp;").join(" ");
  33.         document.getElementById("default_expense_account").value= str;
  34.         document.getElementById("expense_account1").value= str; 
  35.         document.getElementById("expense_more_sok1").disabled= false; 
  36.         str = values_array[3] ;
  37.         str = str.split(";sp;").join(" ");
  38.         document.getElementById("payment_term").value= str;
  39.         strPeriod = calcPeriod(str,document.getElementById("due_date").value);
  40.         document.getElementById("expense_period1").value = (strPeriod); 
  41.         strExpenseDate = calcExpenseDate(str,document.getElementById("due_date").value);
  42.         document.getElementById("expense_date1").value = (strExpenseDate); 
  43.         str = values_array[4] ;
  44.         str = str.split(";sp;").join(" ");
  45.         document.getElementById("expense_account_name1").value= str;
  46.         str = values_array[5] ;
  47.         str = str.split(";sp;").join(" ");
  48.         document.getElementById("expense_vat_code1").value= str;
  49.         if (str == 0) { 
  50.             document.getElementById("expense_vat_flag1").checked= '';
  51.             document.getElementById("expense_vat_flag1").disabled= true;
  52.         }else{
  53.             document.getElementById("expense_vat_flag1").checked= 'yes';
  54.             document.getElementById("expense_vat_flag1").value= 'on';
  55.             document.getElementById("expense_vat_flag1").disabled= false;
  56.         }
  57.         str = values_array[6] ;
  58.         str = str.split(";sp;").join(" ");
  59.         document.getElementById("supplier_name").value= str;
  60.         var str  = values_array[7];
  61.         str = str.split(";sp;").join(" ");
  62.         str = str.split("&cr;").join("\r");
  63.         document.getElementById("netbank_supplier_name_info").value= str;
  64.         strx = justNumberNF(document.getElementById("amount").value);
  65.         document.all["expense_vat_amount1"].value = NetbankToDollarsAndCents(strx * (24/124)) ;
  66.         document.getElementById("amount").value=NetbankToDollarsAndCents(strx);
  67.         document.getElementById("expense_amount1").value = document.getElementById("amount").value;
  68.  
  69.         document.getElementById("expense_amount2").value = '';
  70.         document.getElementById("expense_account2").value= '';
  71.         //document.getElementById("expense_vat_flag2").value= '';
  72.         document.getElementById("expense_vat_amount2").value= '';
  73.         document.getElementById("expense_amount3").value = '';
  74.         document.getElementById("expense_account3").value= '';
  75.         //.getElementById("expense_vat_flag3").value= '';
  76.         document.getElementById("expense_vat_amount3").value= '';
  77.         document.getElementById("expense_amount4").value = '';
  78.         document.getElementById("expense_account4").value= '';
  79.         //document.getElementById("expense_vat_flag4").value= '';
  80.         document.getElementById("expense_vat_amount4").value= '';
  81.         document.getElementById("expense_amount5").value = '';
  82.         document.getElementById("expense_account5").value= '';
  83.         //document.getElementById("expense_vat_flag5").value= '';
  84.         document.getElementById("expense_vat_amount5").value= '';
  85.         str = values_array[8] ;
  86.         str = str.split(";sp;").join(" ");
  87.         if (str=="2"){
  88.             document.frmName.ButtonSelPeriodisering1.disabled=false;
  89.             document.frmName.ButtonSelPeriodisering1.click();
  90.         }
  91.         winName.close();
  92.     }
  93. }
  94.  
  95. //Pass Data Back to original window
  96. function f_popup_return(as_Value)
  97. {
  98.     var l_return = new Array(1);
  99.     l_return[0] = as_Value;
  100.  
  101.     f_set_home_value(l_return);
  102. }
  103.  
  104. function justNumberNF(val){
  105.         val = (val==null) ? 0 : val;
  106.         // check if a number, otherwise try taking out non-number characters.
  107.         if (isNaN(val)) {
  108.            var newVal = parseFloat(val.replace(/[^\d\.\-]/g, '.'));
  109.          // check if still not a number. Might be undefined, '', etc., so just replace with 0.
  110.            return (isNaN(newVal) ? 0 : newVal);
  111.         }
  112.         // return 0 in place of infinite numbers.
  113.         else if (!isFinite(val)) { return 0; }
  114.  
  115.         return val;
  116. };
  117. function NetbankToDollarsAndCents(n) { 
  118.     var s = "" + Math.round(n * 100) / 100  ;
  119.     var i = s.indexOf('.') ;
  120.     if (i < 0) {return s + ",00" } ;
  121.     var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3) ;
  122.     if (i + 2 == s.length) {t += "0"} ;
  123.     return t.replace('.',',') ;
  124.     }
Apr 30 '10 #20
I do really don't like to view codes.
Apr 30 '10 #21
gits
5,390 Expert Mod 4TB
@leendon023: what should that help?

to the question above:

does the page has an element with an id 'supplier_no'?

kind regards
Apr 30 '10 #22

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

Similar topics

14
by: tshad | last post by:
I posted this on the asp.net group, also. I wasn't sure whether this was an asp.net problem or a javascript problem. I have a page that was originally created from a program I found on the net...
5
by: Derek Erb | last post by:
I am banging my head against the wall with this one. The following code snippets work perfectly fine in MSIE6. But produce an error in Firefox and do not work at all. BROWSER.HTM <HTML> .......
11
by: lkrubner | last post by:
We are working on a website that is here: http://www.lauradenyes.com/ The site was working till I put up an .htaccess file that was suppose to redirect all html files to the PHP parser. The...
14
by: David Blickstein | last post by:
I have some XML documents that I want to open in a web browser and be automatically translated to HTML via XSLT. I'm using an xml-stylesheet processing command in a file called "girml.xml". ...
3
by: KBuser | last post by:
I recently developed an internal website with various queries against our SQL server. I added buttons with Response.Redirect. These buttons do not work with Internet Explorer, however when using...
4
by: puja | last post by:
hi all, I have an asp.net website where am including .css file dynamically on page load event. For diff users, there is diff CSS file. So after user logs in, I am setting CSS href on page load....
28
by: entfred | last post by:
I have the following line of html: &nbsp;&nbsp1234&nbsp;&nbsp;&nbsp;&nbsp;&nbspabc&nbsp;&nbsp;&nbspyow In Internet Explorer 6.0, the columns look ok using the above html: 1234 abcd ...
3
by: Arodicus | last post by:
I have a static class method, MyObject.MySub.MyMethod(), which points to a handler in a Flash SWF (but I think that's inconsequential). In reality, the path is a lot longer, so I'd like to make a...
13
by: Stever1975 | last post by:
I'm working on something similiar to a shopping cart item page. There is a table of items. Each item has an image, a textbox for the qty and an image for the add button. When the add image is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.