Whing Dela Cruz
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("B ike").chec ked;
if (c.checked=true)
{
alert("True");
}
else
{
alert("False");
}
}
</script>
<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</
<script>
function iCheck()
{
var c = document.getElementById("B
if (c.checked=true)
{
alert("True");
}
else
{
alert("False");
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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!
These two lines of your code are wrong:
var c = document.getElementById("B
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.