radiobuttons show/hide divs IE

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ciary
    Recognized Expert New Member
    • Apr 2009
    • 247

    radiobuttons show/hide divs IE

    hey all,

    i have a problem with radio buttons showing and hiding divs in IE. i can't figure out what the problem is. when i click on the radiobutton nothing changes. it's only when i click somewhere else, it changes. can someone tell me how i can change it instantly.

    here is a my html sample:
    Code:
    <form name='Sel'>
       <input type='radio' name='selector' value='val1' id='val1' checked=true onchange='Change()'/>  //also tried onclick
       <label>val1</label>
       <input type='radio' name='selector' value='val2' id='val2' onchange='Change()'/>  //also tried onclick
       <label>val2</label>
    </form>
    <div id='switchable1' style='display: block'>
       <p>val1</p>
    </div>
    <div id='switchable2' style='display: none'>
       <p>val2</p>
    </div>
    and this is my javascript function:
    Code:
    			function Change(){
    				if (document.Sel.selector[0].checked){
    					$("switchable1").style.display = "block";
    					$("switchable2").style.display = "none";
    					accessSQL=true;
    				}
    				if (document.Sel.selector[1].checked){
    					$("switchable1").style.display = "none";
    					$("switchable2").style.display = "block";
    					accessSQL=false;
    				}
    			}
    nice detail, it does work in FF.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    That's because you're using onchange. Use onclick instead.

    Comment

    • Ciary
      Recognized Expert New Member
      • Apr 2009
      • 247

      #3
      i thought so too therefor i tried it already. and it gives the same problem. it seems like IE only changes the checked value after the onclick- and onchange-event.

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        I tested your code in IE6/7 using onclick and it worked fine.

        Comment

        • RamananKalirajan
          Contributor
          • Mar 2008
          • 608

          #5
          OnClick events works on both IE and Mozilla as well, The code what u had given is working in Mozilla...

          Regards
          Ramanan Kalirajan

          Comment

          • Ciary
            Recognized Expert New Member
            • Apr 2009
            • 247

            #6
            well then i'm not sure what i'm doing wrong cause it doesn't work here. i've tried both onclick and onchange and nothing really changes.

            to RamananKaliraja n: yep, in mozilla it works fine. the problem lies with IE (as always, people should stop using it:p)

            Comment

            • acoder
              Recognized Expert MVP
              • Nov 2006
              • 16032

              #7
              Perhaps the problem is how your dollar $() function is defined. I just replaced that with document.getEle mentById().

              Comment

              • Ciary
                Recognized Expert New Member
                • Apr 2009
                • 247

                #8
                never had any problem with prototype(cause it's a part from that framework), but i'll try as soon as possible. i dont have the code here atm so ill do it tomorrow.

                Comment

                • acoder
                  Recognized Expert MVP
                  • Nov 2006
                  • 16032

                  #9
                  In that case, it may well be some other code on the page that's affecting things. If you just test the code you've posted, it should work.

                  Comment

                  • Ciary
                    Recognized Expert New Member
                    • Apr 2009
                    • 247

                    #10
                    ok, i solved the problem with onclick and still using prototype

                    how?: by restarting my computer :-o
                    ???

                    i have no idea why it didn't work before and even less why it does now but it does and thats what matters.

                    ty acoder, ty Ramanan

                    Comment

                    • acoder
                      Recognized Expert MVP
                      • Nov 2006
                      • 16032

                      #11
                      Oh, one of those! Restart the computer and everything works fine. Glad it's now working.

                      Comment

                      • RamananKalirajan
                        Contributor
                        • Mar 2008
                        • 608

                        #12
                        May be its due to the temp variables and temp files.. that may be bothering you, but i am not sure.. I am glad that you got it working..

                        Regards
                        Ramanan Kalirajan

                        Comment

                        Working...