3
 <Select id="chkProduct" multiple="true" class="form_input1" placeholder="Product">
   <option selected disabled>Product</option> 
   </select>    


 $(function () {

    $(document).ready(function() {
     var hi = window.localStorage.getItem("rohil");

        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
           url: 'http://202.71.16.74/news/Service.svc/GetContactData',
            data: '{"ContactID":"' + hi +'"}',
            dataType: "json",
            processData: false,
            success: function (data) {

      $("#branchname").val(data.d.Data[0].BranchName);
       $("#add1").val(data.d.Data[0].Address1);
       $("#chkProduct").val(data.d.Data[0].Product);

            },
            error: function (result) {
                alert("Error");
            }
        });

    });
  });

above is the image i want to get checked checkbod after getting the value in string (i.e aa,dd,ee)

want value aa be checked ,dd be checked

Rohil Patel
  • 235
  • 2
  • 4
  • 16

1 Answers1

0

i would try using jquery to change checkbox status.

   <script>
   $(document).ready(function(){//jQuery document function. Is called only once!     
       if(document.getElementById("string").innerHTML == 'smth'){
//Takes your string inner html- what you have written. 
           document.getElementById("myCheck1").checked = true; 
           document.getElementById("myCheck2").checked = true;
//makes your first and second checkbox checked
       }
    });
    </script>

to check by classname change the lines of document.getElementById with:

       document.getElementsByClassName("check")[0].checked = true;
       document.getElementsByClassName("check")[1].checked = true;

This works only if your string is already present! Otherwise you can try adding onkeyup function.

<script type="text/javascript">
 function myfunction() {
      //do smth
      return;
 }
</script>
<input type="text" name="foo" onKeyUp="return myfunction()" />
Luke359
  • 447
  • 6
  • 14