Link to home
Start Free TrialLog in
Avatar of Whing Dela Cruz
Whing Dela CruzFlag for Anguilla

asked on

Check box

Hi experts, I want to get the value of the check box. Please correct code below. Thank you!

<!DOCTYPE html>
<html>
<body>

  <input id="cb" type="checkbox" name="vehicle" value="Bike" checked> I have a bike<br>
  <button onclick="return Get()">Check now</button>
  
  <script>
  function Get()
  {
    var x = document.getElementById("cb").value;
    if (x.checked == true)
    {
      alert(x);
    }
    else
    {
      x = "No bike"
      alert(x);
    }
  }
  </script>

</body>
</html>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Sergio Pacheco Jiménez
Sergio Pacheco Jiménez
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Whing Dela Cruz

ASKER

Thanks Sergio, its working...