Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    New Coder
    Join Date
    Mar 2006
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Firefox and getElementById Problem

    Hi,

    I think from what I have been reading that Firefox has quite a problem with some Javascript. We had this little script written for us which works great in IE but I have no clue how to get it to work with Firefox. Any ideas would be greatly appreciated!

    Code:
    <script type="text/javascript">
    <!--
    function getObject(obj) {
      var theObj;
      if(document.all) {
        if(typeof obj=="string") {
          return document.all(obj);
        } else {
          return obj.style;
        }
      }
      if(document.getElementById) {
        if(typeof obj=="string") {
          return document.getElementById(obj);
        } else {
          return obj.style;
        }
      }
      return null;
    }
    
    function checkqty(item1,item2) {
      var item1Obj=getObject(item1);
      var item2Obj=getObject(item2);
      if (item1Obj.checked == true) {
    	item2Obj.value = "1";
      }
      else if (item1Obj.checked == false) {
    	item2Obj.value = "0";
      }
    }
    //-->
    </script>
    
    <input type="checkbox" name="item2" value="012345" onClick="checkqty('item2','quantity2');">
    <input type="hidden" name="quantity2" value="0">
    Last edited by pootlecat; 08-25-2006 at 07:09 PM.

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by pootlecat
    Hi,

    I think from what I have been reading that Firefox has quite a problem with some Javascript. We had this little script written for us which works great in IE but I have no clue how to get it to work with Firefox. Any ideas would be greatly appreciated!
    Fx actually IMO has better support for most javascript than IE does. Of course users saying Firefox doesn't support something when their script doesn't work when in actuallity its their coding that is wrong in the first place. You currently are passing a name to the getObject function. Since Fx supports document.getElementById() its looking for an id not a name which is why it doesn't work. IE thinks a name is the same as an id but it also understands document.all in which case it will use the name. Add the stuff in bold and your script should work.
    Code:
    <input type="checkbox" name="item2" id="item2" value="012345" onClick="checkqty('item2','quantity2');">
    <input type="hidden" name="quantity2" id="quantity2" value="0">
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #3
    New Coder
    Join Date
    Mar 2006
    Posts
    40
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Thanks so much worked like a charm - I will never malign it's good name again ;P

  • #4
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,
    I have a problem with the following Javascript that works in localhost but doesn't work in FF and in IE

    Code:
                 <span class="ghost" id="infoPro[98]"><?=$image->fields["cprownum"]?></span>
                 <span class="ghost" id="infoPro[99]"><?=$row->fields["cod_dat"]?></span>
    Code:
          <div class="button">
          <form method="POST" id="prenota" action="javascript:cat_changeurl()">
          <input type="submit" class="go" value="prenota" name="prenota">
      	  </form>
          </div>
    Code:
    	<script type="text/javascript">
    	  function cat_changeurl(){
    	  	var img = document.getElementById('infoPro[99]').innerHTML;
    	  	var num = document.getElementById('infoPro[98]').innerHTML;
            window.location.href = "index.php?cp=<?=$_CONFIG["cms_prenota"]?>&img="+img+"&num="+num+"&off="+"n";
    	  }
    <script>
    When i click on submit button, the new URL doesn't read img and num values.

    Thanks in advance

  • #5
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    anything in the error console?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #6
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    anything in the error console?
    No

    I want: ../index.php?cp=238&img=117&num=1&off=n

    but i have: ../index.php?cp=238&img=&num=&off=n

  • #7
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, i resolved using tag <name> in the html code and getAttribute function, as follows:

    Code:
                 <span class="ghost" name="<?=$image->fields["cprownum"]?>" id="infoPro[98]"><?=$image->fields["cprownum"]?></span>
                 <span class="ghost" name="<?=$row->fields["cod_dat"]?>" id="infoPro[99]"><?=$row->fields["cod_dat"]?></span>
    Code:
    	<script type="text/javascript">
    	  function cat_changeurl(){
    	  	var img = document.getElementById('infoPro[99]').getAttribute('name');
    	  	var num = document.getElementById('infoPro[98]').getAttribute('name');
            window.location.href = "index.php?cp=<?=$_CONFIG["cms_prenota"]?>&img="+img+"&num="+num+"&off="+"n";
    	  }

  • #8
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    does it work if you use .textContent?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #9
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    does it work if you use .textContent?
    No, if i use .textContent and not .GetAttribute('name') it doesn't work.
    In local it works...

  • #10
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PSampras View Post
    No, if i use .textContent and not .GetAttribute('name') it doesn't work.
    In local it works...
    I'm sorry, i have to correct myself...
    .innerHTML and .textContent work in local but don't work on web.

    .getAttribute('name') doesn't work nor in local nor on web.

    Please help me...

  • #11
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    do you have a test page?
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #12
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    do you have a test page?
    I have this page.

    If user is logged, he views a button and he can reserved the carpet.
    I need to pass two parameters (infoPro[98] and infoPro[99]) that are "hidden" in this page (you can easily view them in the html code).

    Thanks!

  • #13
    Senior Coder Dormilich's Avatar
    Join Date
    Jan 2010
    Location
    Behind the Wall
    Posts
    3,291
    Thanks
    13
    Thanked 345 Times in 341 Posts
    tested it in FF 3.6 and it worked.
    The computer is always right. The computer is always right. The computer is always right. Take it from someone who has programmed for over ten years: not once has the computational mechanism of the machine malfunctioned.
    André Behrens, NY Times Software Developer

  • #14
    New Coder
    Join Date
    May 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Dormilich View Post
    tested it in FF 3.6 and it worked.
    I have also FF 3.6.3.
    The information on the left box change correctly, if you click on other image.
    But, if you click on button "prenota" (visibile after login) new page doesn't read the info needed to view the correct carpet.
    Try please using
    user: testjs
    pwd: test_js

    Thanks!

  • #15
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    Quote Originally Posted by PSampras View Post
    Ok, i resolved using tag <name> in the html code and getAttribute function, as follows:
    Wrong. A SPAN element can not bear a name attribute. On the other hand it is impossible that innerHTML not to work.

    The problem is that you have not isolated that piece of code within a CDATA island. Under a XHTML Doctype some Javascript special characters are interpreted in an XML way if they are not isolated. Your code will simply be blocked when the interpreter meets the & character. Add the blue:
    Code:
    <script type="text/javascript">
    /*<![CDATA[*/
    	  function cat_changeurl(){
    	  	var img = document.getElementById('infoPro[99]').innerHTML;
    	  	var num = document.getElementById('infoPro[98]').innerHTML;
            window.location.href = "index.php?cp=238&img="+img+"&num="+num+"&off="+"n";
    	  }
    	  
    	  function off_changeurl(){
    	  	var img = document.getElementById('infoPro[99]').innerHTML;
    	  	var num = document.getElementById('infoPro[98]').innerHTML;
            window.location.href = "index.php?cp=238&img="+img+"&num="+num+"&off="+"y";
    	  }
    /*]]>*/
    	</script>
    Last edited by Kor; 05-19-2010 at 11:32 AM.
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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