mercredi 21 décembre 2016

How can i can write jquery validtion for check box

Image of skills required From the above image i have a add more functionality, So my question is for every skill GD (or) PI (or) both check boxes has to be mandatory.(Atleast one check box has to be selected) how can i do that.? this is my html:

<a class="text-center btn btn-danger addSkills">+ Add Skills</a>
<input class="selectGdSkill" type="checkbox" count="0" id="skill[0][gdskill]" name="skill[0][gdskill]">
<input class="selectPiSkill" type="checkbox" count="0" id="skill[0][piskill]" name="skill[0][piskill]">

this is what i have tried but not working.?

var skillcheck = $("#skill[0][gdskill] :checked");
if (skillcheck.length == 0 || $(skillcheck).val() == "") {
    $("#skillcheck").css({"border-style": "solid", "border-color": "red"});
    $("#warning_message").show();
    $("#warning_message").html('Please select any one or both checkbox for individual skill');
    $("#skillcheck").focus();
    return false;
    } else {
    $("#skillcheck").css({"border-style": "solid", "border-color": "#E9E9E9"});
}

this is add more functionality code:

var skillcount = 1;
$(".addSkills").click(function () {
    $('#jobSkills tr:last').after('<tr>
    <td><input class="searchskill" count="' + skillcount + '" id="skill_' + skillcount + '_title" name="skill[' + skillcount + '][title]" type="text" autocomplete="off"></td><td><input count="' + skillcount + '" id="skill_' + skillcount + '_weightage" name="skill[' + skillcount + '][weightage]" type="text" autocomplete="off"></td>
    <td><select class="wp-form-control" name="skill[' + skillcount + '][type]"><option value="0">Select Test Type</option><option value="1">Practice Test</option><option value="2">Qualifying</option></select></td>
    <td><input  class="selectGdSkill" type="checkbox" count="' + skillcount + '" id="skill[' + skillcount + '][gdskill]" name="skill[' + skillcount + '][gdskill]"></td>
    <td> <input class="selectPiSkill" type="checkbox" count="' + skillcount + '" id="skill[' + skillcount + '][piskill]" name="skill[' + skillcount + '][piskill]"></td>
    <td><span class="removeSkill" id="' + skillcount + '" ><a style="color:red">Remove</a></span></td>
    </tr>');
    skillcount++;
});




Aucun commentaire:

Enregistrer un commentaire