By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,729 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,729 IT Pros & Developers. It's quick & easy.

radiobuttons show/hide divs IE

Ciary
Expert 100+
P: 247
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:
Expand|Select|Wrap|Line Numbers
  1. <form name='Sel'>
  2.    <input type='radio' name='selector' value='val1' id='val1' checked=true onchange='Change()'/>  //also tried onclick
  3.    <label>val1</label>
  4.    <input type='radio' name='selector' value='val2' id='val2' onchange='Change()'/>  //also tried onclick
  5.    <label>val2</label>
  6. </form>
  7. <div id='switchable1' style='display: block'>
  8.    <p>val1</p>
  9. </div>
  10. <div id='switchable2' style='display: none'>
  11.    <p>val2</p>
  12. </div>
and this is my javascript function:
Expand|Select|Wrap|Line Numbers
  1.             function Change(){
  2.                 if (document.Sel.selector[0].checked){
  3.                     $("switchable1").style.display = "block";
  4.                     $("switchable2").style.display = "none";
  5.                     accessSQL=true;
  6.                 }
  7.                 if (document.Sel.selector[1].checked){
  8.                     $("switchable1").style.display = "none";
  9.                     $("switchable2").style.display = "block";
  10.                     accessSQL=false;
  11.                 }
  12.             }
nice detail, it does work in FF.
May 15 '09 #1
Share this Question
Share on Google+
11 Replies


acoder
Expert Mod 15k+
P: 16,027
That's because you're using onchange. Use onclick instead.
May 15 '09 #2

Ciary
Expert 100+
P: 247
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.
May 15 '09 #3

acoder
Expert Mod 15k+
P: 16,027
I tested your code in IE6/7 using onclick and it worked fine.
May 20 '09 #4

RamananKalirajan
100+
P: 607
OnClick events works on both IE and Mozilla as well, The code what u had given is working in Mozilla...

Regards
Ramanan Kalirajan
May 20 '09 #5

Ciary
Expert 100+
P: 247
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 RamananKalirajan: yep, in mozilla it works fine. the problem lies with IE (as always, people should stop using it:p)
May 20 '09 #6

acoder
Expert Mod 15k+
P: 16,027
Perhaps the problem is how your dollar $() function is defined. I just replaced that with document.getElementById().
May 20 '09 #7

Ciary
Expert 100+
P: 247
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.
May 20 '09 #8

acoder
Expert Mod 15k+
P: 16,027
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.
May 21 '09 #9

Ciary
Expert 100+
P: 247
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
May 21 '09 #10

acoder
Expert Mod 15k+
P: 16,027
Oh, one of those! Restart the computer and everything works fine. Glad it's now working.
May 21 '09 #11

RamananKalirajan
100+
P: 607
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
May 22 '09 #12

Post your reply

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