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

asked on

Html CheckBox obtain Its Value

Hi Experts, I want to get an alert whether the checkbox is true or false. HOW? codes below is not working. Any help please..
<form>
  <input type="checkbox" name="vehicle" value="Bike"> I have a bike<br>
  <input type="submit" value="Submit">
</form>
 <button type=button onclick="iCheck()">Check</button>
  <script>
    function iCheck()
    {
      var c = document.getElementById("Bike").checked;
       if (c.checked=true)
       {
          alert("True");
       }
       else
       {
          alert("False");
       }
    }
   </script>
ASKER CERTIFIED SOLUTION
Avatar of Abhijeet Rananaware
Abhijeet Rananaware
Flag of India 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
I would repost this in the javascript forum. This is NOT java.

These two lines of your code are wrong:

var c = document.getElementById("Bike").checked; // THERE IS NO ELEMENT with ID attribute equals to "Bike"

if (c.checked=true) // c should now be evaluated as a boolean. You should not be calling c.checked on it, you've already done that.
SOLUTION
Avatar of Mukesh Yadav
Mukesh Yadav
Flag of India 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
SOLUTION
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

Thank you Leonidas for adding the solution of Mukesh so then I can uncheck the box. Rananaware was also answered  my first concern but thank you for adding it. More power to all of you!