我如何在单选按钮中发布值并在数据库中显示可用值?

时间:2019-07-09 05:14:56

标签: javascript html django ajax

**i have create dynamic multiple radio button in pair of two in table.i want to show the available value in database value are in true false and i also want when user change value it's update database value.**  

var countemp = 1;

$(comjsonemp).each(function (index, item) {

   var itemnameemp_v = comjsonemp[index].itemid__item_name;
   var requiredemp_v = comjsonemp[index].required;
   var statusemp_v = comjsonemp[index].status;
   var itemidemp_v = comjsonemp[index].itemid;
   var remarksemp_v = comjsonemp[index].remarks;
   var html_emptb;



if(comjsonemp.toString().length > 0){

$(“#div_empfolder”)。show();

如果(requiredemp_v.trim()=='T'){     html_emptb + =“”;' } 其他{     html_emptb + =“”;}

countemp += 1;

单选按钮块     if(statusemp_v.trim()=='T')     {     html_emptb + =“已收到
未收到”;}     其他     {     html_emptb + =“已收到

+countemp+"' class='with-gap radio-col-teal' checked /><label

for='id_empreceived_n" +countemp+"'>Not Received</label>    </td>";
                                 }

html_emptb +=" <td>" + itemnameemp_v + "</td>" ;



html_emptb +="<td><input type='hidden' name='hid_Empitemid_v' id='id_hid_Empitemid_v' value='" + itemidemp_v + "' /></td>";



html_emptb +="<td><textarea rows='2' class='form-control' name='emp_check' id='id_empcheck' value='" + remarksemp_v + "' > </textarea> </td>" ;

}

$("<tr/>").html(html_emptb).appendTo("#id_emp");
                    }); 

1 个答案:

答案 0 :(得分:0)

这是HTML部分

<p>
    <label><input class="rd" type="radio" name="gender" value="male">Male</label>
    <label><input class="rd" type="radio" name="gender" value="female">Female</label>
</p>
<p><input id="btn" type="button" value="Get Value"></p>

javascript部分

$(document).ready(function() {
    $("#btn").click(function() {
        var radioValue = $(".rd:checked").val();
        if (radioValue) {
            alert("Your are a " + radioValue);
        };
    });
});