Radio buttons not getting selected

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kenia
    New Member
    • Dec 2006
    • 7

    Radio buttons not getting selected

    Hi everyone!
    I'm using the DOM standard to create a set of radio buttons, but I can't select any of them. It means that they appear in the page, but when I click on any of them nothing seems to happen. This is the code I've written to create the radio buttons

    var list = document.create Element("table" );
    var tbody = document.create Element("tbody" );
    var values = new Array("Hoy","Ay er","Ultima semana","Este mes","Personali zar");

    for(var i=0; i<values.length ; i++)
    {
    var tr = document.create Element("tr");
    var td = document.create Element("td");
    td.setAttribute ("align","left" );
    var option = document.create Element("input" );
    option.setAttri bute("type","ra dio");
    option.setAttri bute("name","da te");
    option.setAttri bute("value",va lues[i]);

    td.appendChild( option);
    td.appendChild( document.create TextNode(values[i]));

    tr.appendChild( td);

    tbody.appendChi ld(tr);
    }

    list.appendChil d(tbody);

    return list;

    So if any of you sees that something is missing, say an attribute or something like that to make it work, please help me out and reply this.
    Thanks a lot

    Kenia
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    You created the buttons and put them on the screen, but where is the code that captures the button when clicked?

    Ronald :cool:

    Comment

    • AricC
      Recognized Expert Top Contributor
      • Oct 2006
      • 1885

      #3
      If you want to default to one you need to add checked="checke d"

      Comment

      • kenia
        New Member
        • Dec 2006
        • 7

        #4
        Originally posted by ronverdonk
        You created the buttons and put them on the screen, but where is the code that captures the button when clicked?

        Ronald :cool:
        You're right, I haven't written that code, but it's just because I thought that it would be like in the case of the select element in which one you don't have to select the options by yourself, you just attach a function to an event when you want to do something in particular when it fires.
        Anyway, now I have another question, I could do this
        option.onclick = anyFunction;

        But then I would be calling a function with no parameters, so how would I know which was the radio that was clicked? Or how could I attach a function dynamically which I could pass the clicked radio name or id to?

        Thanks again.

        Kenia

        Comment

        Working...