Changing a Label dynamically



Wriite JavaScript code to evaluate checkbox selected by user

<html>
  <head>
    <title>Change Labels </title>
      <script>

          function show(e) 
          {
              const form = document.forms["frm1"];
              const select = form["op1"];
              const button = form["b1"];
              
              if (e === 'State') 
              {
                  button.value = 'City';
                  
                  select.options[0].text = 'Maharashtra';
                  select.options[0].value = 1;

                  select.options[1].text = 'Gujarat';
                  select.options[1].value = 2;

                  select.options[2].text = 'Andhra Pradesh';
                  select.options[2].value = 3;
              } 
              else if (e === 'City') 
              {
                  button.value = 'State';

                  select.options[0].text = 'Pune';
                  select.options[0].value = 1;

                  select.options[1].text = 'Ahmedabad';
                  select.options[1].value = 2;

                  select.options[2].text = 'Vijayawada';
                  select.options[2].value = 3;
              }
          }

      </script>
    </head>
  <body>

<form name="frm1" action="" method="post">

        <select name="op1" size="3">
        <P>

        <option Value=1> Maharashtra 
        <option Value=2> Gujarat 
        <option Value=3> Andhra Pradesh

        </select>
        </P>
        <br>

        <input type="submit" value="Submit" name="submit" >

        <input type="button" value="City" name="b1" onclick="show(this.value)">

    </form>        
  </body>
</html>

Output: