Results 1 to 7 of 7

Thread: question bout ie and firefox behaviour on javascript scripts

  1. #1
    Join Date
    Jan 2010
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default question bout ie and firefox behaviour on javascript scripts

    well firstly, im having this problem where by the javascipt script runs perfectly fine on Firefox browser but it does'nt on IE 8 browsers.

    here's the script :

    Code:
    var i,zform = document.listcases
    
    for (i=1; i<zform.elements.length;i++) {
    			if (zform.elements[i].id == 'cases[]'){	
    				    if(zform.elements[i].checked == true){
    						txtid = zform.elements[i].value.split(':')
    						url += txtid[1] + ','	
    						x++
    					}
    			}
    	}
    cases[] is an array of checkboxes which i would like to detect whether they are checked or not. in IE the loop seems to not able to detect the cases[] elements.

    need help on this problem. thanks
    Last edited by jscheuer1; 03-17-2010 at 10:33 AM. Reason: format code

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Both 'url' and 'x' are undefined. As a result, the code won't work in any browser.

    Now, they may be defined elsewhere that you are not showing us. If this code works in Firefox, they probably are.

    Just guessing though, rather than test for id == 'cases[]', if the elements are named cases[], as would be proper HTML syntax, test for name == 'cases[]'.

    If you want more help:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I did a little experiment. In both IE and Firefox, this 'works':

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    onload = function(){
    	var c = document.listcases.elements;
    	for (var i = c.length - 1; i > -1; --i){
    		if(c[i].id == 'cases[]'){
    			alert('works');
    		}
    	}
    }
    </script>
    </head>
    <body>
    <form action="#" name="listcases">
    <input type="checkbox" id="cases[]" value="">
    <input type="checkbox" id="cases[]" value="">
    </form>
    </body>
    </html>
    So it's not IE's inability to pick up on the invalid id="cases[]" elements, there must be something else that you are not showing us.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Jan 2010
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    yes both the url and x are defined somewhere else.

    but those 2 variables are'nt really that vital. what i really need is to be able to detect the 'cases[]' element with the if statement. these are 2 checkboxes that i have in my html

    <input type="checkbox" id="cases[]" name="cases[]" value="testing1" checked>

    <input type="checkbox" id="cases[]" name="cases[]" value="testing2" checked>

    and yea i've already changed id == 'cases[]' to name == 'cases[]' and the problem is still there.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Still 'works' here in IE:

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script type="text/javascript">
    onload = function(){
    	var c = document.listcases.elements;
    	for (var i = c.length - 1; i > -1; --i){
    		if(c[i].id == 'cases[]' && c[i].checked == true){
    			alert('works');
    		}
    	}
    }
    </script>
    </head>
    <body>
    <form action="#" name="listcases">
    <input type="checkbox" id="cases[]" name="cases[]" value="testing1" checked>
    
    <input type="checkbox" id="cases[]" name="cases[]" value="testing2" checked>
    </form>
    </body>
    </html>
    Sounds like there might be a problem (in your version) with the undeclared variable 'txtid'. Try changing:

    Code:
    txtid = zform.elements[i].value.split(':')
    to:

    Code:
    var txtid = zform.elements[i].value.split(':')
    And testing1 (the value of the checkbox) when split on ':' will have an index [1] of undefined. So (again, in your version):

    Code:
    url += txtid[1] + ','
    would result in 'undefined,' or some other falsey string being added to the existing value of 'url'. Or it might even cause an error.

    But without seeing the page, I can only guess:

    Please post a link to a page on your site that contains the problematic code so we can check it out.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Jan 2010
    Posts
    13
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default

    thanks for ur help ... im sorry i could'nt show more of my codes. but i kind of found the problem it seems there's another form within the listcases form.

    <form action="#" name="listcases">
    <form action "#" name="otherform">
    </form>
    <input type="checkbox" id="cases[]" value="">
    <input type="checkbox" id="cases[]" value="">
    </form>


    i think this is causing a problem in IE but not in Firefox. i would like to ask is there some way to detect all the elements without specifying the form ?? is it possible to get all elements on the page?

    something like that?

    document.elements;


    thanks again.

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Code:
    <form action "#" name="otherform">
    </form>
    <form action="#" name="listcases">
    <input type="checkbox" id="cases[]" value="">
    <input type="checkbox" id="cases[]" value="">
    </form>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •