javascript - Limit to One When the Checkbox is Checked -


i have form want limit data drop downlist when checkbox checked

enter image description here

so when save theres message window appear , let user know he/she checked checkbox 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>                  primary?</label>         </span>         </p>          <p>             <span>                <input type="submit" id="btnadd" class="styledbutton" value="add" />             </span>         </p>     } </div> 

i need validation written in javascript dont know how start :(

thanks

jquery:

if($('#chkworkerisprimary').is(':checked')){    //your code     } 

.is(':checked') if user has checked checkbox returns true, else return false

or javascript:

if ($("[name=chkworkerisprimary]:checked").length == 0){     //your code } 

Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -