javascript - Disable radio button based on previous radio selection -


i need enable radio options based on 2 previous selected radios, have made question on pervious topic , tried unsuccessfully adapt new need, , tried using answer this topic, unsuccessfully...

so here's more details need: select 1 radio each of 2 previous radio groups, @ third group should available (enabled) pick 2 correspond previous selection...

first group: de, en, es, ca (selected)

second group: de, en (selected), es, ca

third group: de (disabled), en (enabled), es (disabled), ca (enabled)

and here code i'm using:

$(document).ready(function() {    $('input[name=lang_or]').click(function() {      $('input[name=lang_tg]').prop('disabled', false);      $('input[name=lang_tg][value=' + this.value).prop('disabled', 'disabled');    });  });
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>  <table>    <tr>      <th>origin language</th>      <th>target language</th>      <th>language index first</th>    </tr>    <tr>      <td>        <label><input type="radio" name="lang_or" value="de">german</label>        <label><input type="radio" name="lang_or" value="en">english</label>        <label><input type="radio" name="lang_or" value="ca">catalan</label>        <label><input type="radio" name="lang_or" value="es">spanish</label>        <label><input type="radio" name="lang_or" value="fr">french</label>        <label><input type="radio" name="lang_or" value="it">italian</label>        <label><input type="radio" name="lang_or" value="pt">portugues</label>      </td>      <td>        <label><input type="radio" name="lang_tg" value="de">german</label>        <label><input type="radio" name="lang_tg" value="en">english</label>        <label><input type="radio" name="lang_tg" value="ca">catalan</label>        <label><input type="radio" name="lang_tg" value="es">spanish</label>        <label><input type="radio" name="lang_tg" value="fr">french</label>        <label><input type="radio" name="lang_tg" value="it">italian</label>        <label><input type="radio" name="lang_tg" value="pt">portugues</label>      </td>      <td>        <label><input type="radio" name="language" value="de">german</label>        <label><input type="radio" name="language" value="en">english</label>        <label><input type="radio" name="language" value="ca">catalan</label>        <label><input type="radio" name="language" value="es">spanish</label>        <label><input type="radio" name="language" value="fr">french</label>        <label><input type="radio" name="language" value="it">italian</label>        <label><input type="radio" name="language" value="pt">portugues</label>      </td>    </tr>  </table>

i changed click listener $('input[name^=lang_]').click(function() { target both first , second group of radio buttons.

now inside click listener, can check those radio buttons checked in first , second group of radio buttons:

$('input[name^=lang_]:checked').each(function() {    $('input[name=language][value=' + $(this).val() + ']').prop('disabled', false); }); 

see demo below:

$(document).ready(function() {      // initialize disabled    $('input[name=language]').prop('disabled', true);      // click listener 1st , 2nd groups    $('input[name^=lang_]').click(function() {      // disable first      $('input[name=language]').prop('disabled', true);      // enable selected radios      $('input[name^=lang_]:checked').each(function() {        $('input[name=language][value=' + $(this).val() + ']').prop('disabled', false);      });    });  });
<script src='https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script>    <table>    <tr>      <th>origin language</th>      <th>target language</th>      <th>language index first</th>    </tr>    <tr>      <td>        <label><input type="radio" name="lang_or" value="de">german</label>        <label><input type="radio" name="lang_or" value="en">english</label>        <label><input type="radio" name="lang_or" value="ca">catalan</label>        <label><input type="radio" name="lang_or" value="es">spanish</label>        <label><input type="radio" name="lang_or" value="fr">french</label>        <label><input type="radio" name="lang_or" value="it">italian</label>        <label><input type="radio" name="lang_or" value="pt">portugues</label>      </td>      <td>        <label><input type="radio" name="lang_tg" value="de">german</label>        <label><input type="radio" name="lang_tg" value="en">english</label>        <label><input type="radio" name="lang_tg" value="ca">catalan</label>        <label><input type="radio" name="lang_tg" value="es">spanish</label>        <label><input type="radio" name="lang_tg" value="fr">french</label>        <label><input type="radio" name="lang_tg" value="it">italian</label>        <label><input type="radio" name="lang_tg" value="pt">portugues</label>      </td>      <td>        <label><input type="radio" name="language" value="de">german</label>        <label><input type="radio" name="language" value="en">english</label>        <label><input type="radio" name="language" value="ca">catalan</label>        <label><input type="radio" name="language" value="es">spanish</label>        <label><input type="radio" name="language" value="fr">french</label>        <label><input type="radio" name="language" value="it">italian</label>        <label><input type="radio" name="language" value="pt">portugues</label>      </td>    </tr>  </table>


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -