简体   繁体   中英

Radio Button not selecting

I am using a razor radio button but one radio button is not selecting not disabled don't know why not selecting Single radio button

在此处输入图片说明

       <div class="col-md-4" style="margin-right:-22%;">
             <div class="form-group">
                 <span> Single </span> @Html.RadioButton("Type", "1", new { onchange = "GetType(this.value)", @required = "required" })
              </div>
          </div>
       <div class="col-md-3">
           <div class="form-group">
               <span> Multiple </span> @Html.RadioButton("Type", "2", new { onchange = "GetType(this.value)", @required = "required" })
                </div>
        </div>

Jquery Code

  function GetType(Type)
            {
                if (Type == 1) {
                    $("#AllDepartments").hide();
                    $("#AllEmployees").show();
                }
                else if(Type == 2)
                {
                    $("#AllEmployees").hide();
                    $("#AllDepartments").show();
                }
            }

Your description it's so low but i think this example will makes understand, because radio buttons must have the same name for example:

<input type="radio" name="asdf">
<input type="radio" name="asdf">

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>radio demo</title> <style> textarea { height: 25px; } </style> <script src="https://code.jquery.com/jquery-1.10.2.js"></script> </head> <body> <form> <input type="button" value="Input Button"> <input type="checkbox"> <input type="file"> <input type="hidden"> <input type="image"> <input type="password"> <input type="radio" name="asdf"> <input type="radio" name="asdf"> <input type="reset"> <input type="submit"> <input type="text"> <select> <option>Option</option> </select> <textarea></textarea> <button>Button</button> </form> <div></div> <script> var input = $( "form input:radio" ) .wrap( "<span></span>" ) .parent() .css({ background: "yellow", border: "3px red solid" }); $( "div" ) .text( "For this type jQuery found " + input.length + "." ) .css( "color", "red" ); // Prevent form submission $( "form" ).submit(function( event ) { event.preventDefault(); }); </script> </body> </html> 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM