0

I have a html page which works with select/option and I want to convert this feature to input type=radio (list to radio butons).

Actually i have a list of selects like this:

<select name="DEC-51537a4b580452b9e145b75c-A">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>

<select name="DEC-51537a4b58045459e145b75c-R">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>

<select name="DEC-51537a88880452b9e145b75c-A">
<option selected="" value="OK">OK</option>
<option value="NOK">NOK</option>
</select>

The user select the value that he want and click on a button.The button call a javascript which get the result for each "DEC-".

For each select which start with "DEC-", I retrieve : - dec-number (51537a88880452b9e145b75c for example) - original dec value (A or R) - and i get select.value in order to retrieve the dec value select by the user

If i want to convert select to input type=radio, first of all I have change select to this:

<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" checked value="A">A
<input name="DEC-51537a4b580452b9e145b75c-A" type="radio" value="R">R

And here the javascript function which works with select but not radio buttons:

  var elements = $doc.getElementsByTagName('select');

  var sel;

  for(var i=0; i<elements.length; i++){
      sel = elements[i];

       if(sel.name.indexOf('DEC-') === 0){
          var selName = sel.name.split('-');
          var oid = selName[1];
          var originalDecision = selName[2];
          var supervisorDecision = sel.value;

          decisions++;
          if(originalDecision == supervisorDecision) {
              rightDecisions++;
          } else {
              wrongDecisions++;

              if(originalDecision == "ACCEPTED") {
                  originalDecision="<h3 class='green'>ACCEPTED</h3>";
              } else if(originalDecision == "REFUSED") {
                  originalDecision="<h3 class='red'>REFUSED</h3>";
              }

              if(supervisorDecision == "ACCEPTED") {
                  supervisorDecision="<h3 class='green'>ACCEPTED</h3>";
              } else if(supervisorDecision == "REFUSED") {
                  supervisorDecision="<h3 class='red'>REFUSED</h3>";
              }

              var content = $doc.getElementById(oid).innerHTML;
              wrongDecisionsTab += "<tr><td>" + content + "</td><td>" 
               + originalDecision + "</td><td><h3>" + supervisorDecision + "</h3></td></tr>";
          }

      }

  }

I need the same things but with radio buttons, so i have tried to change:

  var elements = $doc.getElementsByTagName('input');

but it's not sufficient. What i'm missing?

AndreyAkinshin
  • 18,603
  • 29
  • 96
  • 155
superscral
  • 480
  • 1
  • 11
  • 33
  • 2
    Why don't you just rewrite the HTML ? – adeneo Mar 29 '13 at 07:46
  • because users prefer to select the decision in one click and not 2 click – superscral Mar 29 '13 at 07:53
  • I don't think you understood me, why are you asking for a javascript solution, when all you have to do is change the HTML to use radio's ? – adeneo Mar 29 '13 at 08:00
  • 1
    I agree that in this case radio buttons are the way to go, but as @adeneo said, why don't you just change the HTML? I think we are missing part of your problem here. Also, your question seems incomplete. You write "first of all I have change select to this:" but nothing relevant follows... – excentris Mar 29 '13 at 08:06
  • Maybe you are looking for something like [this](http://stackoverflow.com/questions/2029267/jquery-convert-select-to-radio-buttons). – excentris Mar 29 '13 at 08:08
  • Thanks but i can't use jquery, only javascript (GWT/JSNI) – superscral Mar 29 '13 at 08:20
  • I have changed select option to radio button but then when i execute javascript it's dont working, so I tried to see why – superscral Mar 29 '13 at 08:25
  • Not sure if I am missing something, but on your code you seem to be checking `if(originalDecision == "ACCEPTED")` while the split part of the name from the radio/select you are checking against only contains an 'A'. – excentris Mar 29 '13 at 09:00

0 Answers0