jeudi 23 avril 2020

JS or Jquery: how to add an "option" to a checkbox

The checkbox created in MS Sharepoint form has this html structure;

<div class="fd_field " fd_name="purchase_order" style="">
  <div class="fd_title" style="width: 150px;">purchase_order</div>
  <div class="ms-formbody fd_control" fd_type="MultiChoice">
    <span dir="none">
      <table cellspacing="1" cellpadding="0">                             
        <tbody>
          <tr>
            <td><span class="ms-RadioText" title="Carica dati">
              <input id="ctl00_ctl40_g_2bbe8d3f_1b61_4103_9ca6_2e943eb28860_purchase_orderField_ctl00_ctl00" type="checkbox" name="ctl00$ctl40$g_2bbe8d3f_1b61_4103_9ca6_2e943eb28860$purchase_orderField$ctl00$ctl00">
              <label for="ctl00_ctl40_g_2bbe8d3f_1b61_4103_9ca6_2e943eb28860_purchase_orderField_ctl00_ctl00">Carica dati</label></span>
            </td>
        </tr>
      </tbody>
    </table>
    </span>
  </div>
</div>

with ajax i got other data that i want to add as option in that checkbox. The loop to retrieve data is not a problem but, how can i append those data in a new row of the checkbox? In the past i was able to edit dropdown field but it not works with checkbox.

I was thinking to the a solution like this:

var f = '<tr><td><input type="checkbox" name="xxx" id="ss"><label for="ss">Other</label></td></tr>';
$( ".ms-RadioText" ).parent().append(f);

Thanks




Aucun commentaire:

Enregistrer un commentaire