Document objects and check boxes (JavaScript Getting Started Tutorial V)

Source: Internet
Author: User

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title> New Document </title>
<script language= "javascript" type= "Text/javascript" >
<!--
function SayHello () {
document.write ("<strong>hello</strong>");
}
-->
</script>
<body>
<script language= "javascript" type= "Text/javascript" >
<!--
SayHello ();
-->
</script>

</body>

Look at an instance that gets the checkbox value

<!doctype HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >
<title> New Document </title>
<body>

<form action= "somepage.asp tutorial" name= "Theform" >
<dl>
<dd><input type= "checkbox" Name= "Option1"/> Multiple personalities </dd>
<dd><input type= "checkbox" Name= "Option2"/> Lotte Philosophical </dd>
<dd><input type= "checkbox" Name= "Option3"/> Mature and stable </dd>
<dd><input type= "checkbox" Name= "Option4"/> Childish naughty </dd>
<dd><input type= "checkbox" Name= "Option5"/> Gentle and considerate </dd>
<dd><input type= "checkbox" Name= "Option6"/> Lively and lovely </dd>
<dd><input type= "checkbox" Name= "option7"/> Ordinary </dd>
<dd><input type= "checkbox" Name= "Option8"/> Introverted shyness </dd>
<dd><input type= "checkbox" Name= "Option9"/> Outgoing and cheerful </dd>
<dd><input type= "checkbox" Name= "Option10"/> Wit </dd> Humor
</dl>
<input name= "Submit" type= "Submission" value= "submitted"/>
</form>
</body>

<script language= "javascript" type= "Text/javascript"
<!--
Document.forms[0].elements["Submit" ].onclick=function () {
 var checkedcount=0; //statistics selected
 for (Var i=0;i<document.forms[0]. elements.length;i++) { //traverse all check boxes
  if (document.forms[0].elements[i].checked) checkedcount++;
&NBSP}
 if (checkedcount>5 | | checkedcount<3) {
  alert ("The number of options is at least 3, no more than 5");
   return false; //does not meet the requirements, returns false to cancel submitting
 
 return true;
}
//-->
</script>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.