Shazma Batool

Shazma Batool

  • 2k
  • 86
  • 1.6k

Select an option makes a checkbox checked

May 18 2022 9:52 AM

I want to select an option from the select tag in html containing 2 options and based on the option I have selected a related checkbox gets checked how can I achieve this? Here is my code:



 <select id="select" onclick="Select()">

        <option value="Select" selected >Select</option>

        <option value="Lahore" id="lahore" >Lahore</option>

        <option value="Karachi" id="karachi">Karachi</option>



function Select()


var Option=document.getElementById("select").value;


    document.getElementById("chkbox-lahore").checked = true;



    document.getElementById("chkbox-karachi").checked = true;



PS. How can I do this with jQuery? Thanks

Answers (8)