Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: Web
Expertise: Intermediate
Jul 27, 1999

Verify a Check Box Using JavaScript

It is possible to see if a check box has been checked or not in JavaScript. This may come in handy during form validation. A check box has a checked property, which returns either a 0 for not checked and a 1 for checked. You can also set the property to 0 or 1 to programmatically control the check box.

 
<html>
<head>
<script language=javascript>
function validate(chk){
  if (chk.checked == 1)
    alert("Thank You");
  else
    alert("You didn't check it! Let me check it for you.")
    chk.checked = 1; 
}
</script>
</head>
<body>
<form>
<input type=checkbox name=chk1>Please Check Me
<p><input type=button value="check" onclick="return validate(chk1);">
</form>
</body>
</html>
William Wen
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap