html - javascript disable a single radio button -


i have should problem simple solution, , i'm sure i'm missing something.

i have 2 columns of radio buttons, , when radio button column clicked, need disable corresponding radio button opposite column, can't selected. if button selected, re-enable previous button , disable new opposite selection.

i have given radio buttons unique id. first1, first2, etc. column one, , second1, second2 etc. column two.

the way headed towards won't work after re-thinking this, , after searching online hour, haven't found non-jquery way of doing it. possible javascript?

what had far, , know i'm way off base, i'm burnt out different problems i've had page:

function disableform(theform, theradio) {     //this start does't save valid disabled fields     //it enables     if (document.all || document.getelementbyid) {         (i = 0; < theform.length; i++) {         var formelement = theform.elements[i];             if (true) {                 formelement.disabled = false;             }         }      }      document.getelementbyid(theradio).onclick = function(){         document.getelementbyid(theradio).disabled=true;     } } 

let's define radios as

<table style="width: 100%;">         <tr>             <td>                 <input id="radio1_1" type="radio" name="radio1" onchange="process(this)"/><br />                 <input id="radio1_2" type="radio" name="radio1" onchange="process(this)"/><br />                 <input id="radio1_3" type="radio" name="radio1" onchange="process(this)"/><br />                 <input id="radio1_4" type="radio" name="radio1" onchange="process(this)"/><br />                 <input id="radio1_5" type="radio" name="radio1" onchange="process(this)"/>             </td>             <td>                 <input id="radio2_1" type="radio" name="radio2" /><br />                 <input id="radio2_2" type="radio" name="radio2" /><br />                 <input id="radio2_3" type="radio" name="radio2" /><br />                 <input id="radio2_4" type="radio" name="radio2" /><br />                 <input id="radio2_5" type="radio" name="radio2" />              </td>          </tr>      </table> 

then goal can achieved simple script:

 function process(rb) {     //clearing previos disabled    (i = 0; < document.getelementsbyname("radio2").length; i++) {        document.getelementsbyname("radio2")[i].disabled = '';    }    document.getelementbyid(rb.id.replace('radio1','radio2')).disabled='disabled';  } 

working example: http://jsfiddle.net/bbgda/1/


Comments

Popular posts from this blog

plot - Remove Objects from Legend When You Have Also Used Fit, Matlab -

java - Why does my date parsing return a weird date? -

Need help in packaging app using TideSDK on Windows -