Javascript Radio button Exercise with working code and output snaps - DOM Manipulation Exercise

Javascript Radio button Exercise with working code and output snaps


So here is the working code(Just copy and paste in your text editor):


<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Javascript Radio button Exercise with working code and output snaps</title>
</head>


<body>

    <div class="wrapper">
        <div id="header">

          <h1 class="header-tag" style="text-align:center; color:red;">EXERCISE</h1>

        <input type="radio" name="radio1" id="box1" value="RUSTIC TRAVEL JUNKIE">RUSTIC TRAVEL JUNKIE</input><br><br>
        <input type="radio" name="radio1" id="box2" value="CODING GURU 99" >CODING GURU 99</input><br><br>

          <button onclick="box()">CLICK ME</button>
          <script>

            function box(){

              var a = document.getElementById("box1");
              var b = document.getElementById("box2");

              if(a.checked==true)
              {alert(" YOU HAVE CHOSEN : " + a.value);}

              else if (b.checked ==true)
                {
                  alert("YOU HAVE CHOSEN :" + b.value);
                }
              else {
                alert("nothing selected");
              }

              }

  </script>
</body>
</html>

HERE IS THE OUTPUT OF THE ABOVE CODE:



Comments

Popular posts from this blog