2

I have HTML code like so:

function toggle_action(type) {
var tabs = document.getElementsByName("action_tab")
for(var i = 0 ; i < tabs.length; i++){
    //alert(" i = " + i + " length=" + tabs.length );
    if(tabs[i].id == type.value){
        tabs[i].style.display='inline';
    }else{
        tabs[i].style.display='none';
    }
};
}

a

<div id="action_types">
   <input type="radio" checked name="action_type" value="EmailActionDescription"  onclick="toggle_action(this);"/><label>Email</label>
   <input type="radio" name="action_type" value="TicketActionDescription" onclick="toggle_action(this);"/><label>Ticket</label>
</div>

it works fine in firefox but doesn't work in internet explorer.

any ideas what it could be? the buttons basically display one of 2 options, a ticket or e mail, when clicking on the ticket it just doesn't show.

if you require any further information please let me know.

thanks

Mo.
  • 40,243
  • 37
  • 86
  • 131
  • The code is incomplete. Please update your question to include a **minimum** copy'n'paste'n'runnable example from `` until with `` which reproduces exactly the whole problem. With *minimum* I mean, no unnecessary/irrelevant classes/elements/scripts/etc. – BalusC May 27 '10 at 11:29
  • How does it fail to work in IE? – Matchu May 27 '10 at 11:31
  • Nothing happens when you click on the Ticket radio button. it just stays on EmailActionDescription, i cant really put all the code up as page i'm viewing/working on is 6 different HTML files and is linked to a lot of JavaScript code, so you can really reproduce it. i was just seeing if any one might have had any ideas, and i appriciate every ones input and sugestions. – Mo. May 27 '10 at 11:51
  • What happens if you delete the onClick argument ? Do the radio buttons work normally ? Because it looks like the problem comes from toggle_action() so we won't be able to help you without more details – Jla May 27 '10 at 12:00
  • Copy your page, delete ALL irrelevant code and post it here as example. Else we simply can't reliably answer this question. As far now it's shooting in the dark (the suggestion of John topley is nice, but is truly not the problem since IE already doesn't understand XHTML and handles everything as HTML). It's like going to a car mechanican and telling "my car is broken, please fix it" without coming with the car. – BalusC May 27 '10 at 12:19

3 Answers3

1

You don't state which DOCTYPE you're using (if any), but certainly with XHTML attributes have to have values, which your checked attribute doesn't have. You could try this:

<input type="radio" checked="checked" name="action_type" value="EmailActionDescription"  onclick="toggle_action(this);"/><label>Email</label>
John Topley
  • 113,588
  • 46
  • 195
  • 237
1
var tabs = document.getElementsByName("action_tab")

First, getElementsByName() is broken in IE. Rather use getElementsByTagName() and/or getElementById(). Or better, use jQuery and $('[name=action_tab]').

Second, this sounds like as <div name="action_tab"> and so on. The HTML <div> element doesn't have a specified name attribute and I doubt if a custom name attribute will work that way in IE with getElementsByName().

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

Since you don't post your toggle_action() code I can only guess that the problem is in that function. And probably if the function fails, the radiobutton selection routine is canceled.

What do you use the toggle_action() routine for?

Christian Wattengård
  • 5,543
  • 5
  • 30
  • 43