0

I have a Form where I want to limit the Data from my Drop Downlist when the checkbox is checked

enter image description here

So that When i Save theres a Message window that will Appear and Let the user know that he/she checked the checkbox for the Same Drop Down Value

using (Html.BeginForm("Save", "Worker", FormMethod.Post, new { id = "contactForm" }))
{
    <input type="hidden" id="workerId" name="workerId" value="@workerId" />
    <p>
        <label for="ddlContactType">
            Contact Type</label>
        <span>
             @Html.DropDownList("ddlContactType", new SelectList(ViewBag.ContactTypeList, "ID", "Display_Value", workerContactType), "[Please Select]",
                new Dictionary<string, object>
                {
                    {"class","validate[required] inputLong"}
                })
        </span>
    </p>
    <p>
        <label for="txtContactValue">
            Contact Value</label>
        <span>
            <input type="text" id="txtContactValue" name="txtContactValue"  class="validate[required] inputLong" value="" />
            <input type="checkbox" name="chkWorkerIsPrimary" id="chkWorkerIsPrimary" value="true"
                        checked="checked" />
             <label>
                 Is Primary?</label>
        </span>
        </p> 
        <p>
            <span>
               <input type="submit" id="btnAdd" class="styledButton" value="Add" />
            </span>
        </p>
    }
</div>

I need the Validation written in Javascript but i dont know how to start :(

Thanks

4

1 回答 1

0

查询:

if($('#chkWorkerIsPrimary').is(':checked')){
   //Your code    
}

.is(':checked') 如果用户选中了复选框,则返回 true,否则返回 false

或 javascript:

if ($("[name=chkWorkerIsPrimary]:checked").length == 0){
    //your code
}
于 2013-07-18T11:56:45.027 回答