Jump to content

  • Free consultations and support
  • Live chatClick Here for Live Chat
  • Call ico 1888-906-1888
    Phone support: Open

    Ready for your call :)

    Our business hours:

    Mon — Fri, 2am — 8pm (EST)

    US & EU support teams

    Phone support: Closed

    We are back in: 1h 20m

    Our business hours:

    Mon — Fri, 2am — 8pm (EST)

    US & EU support teams


Adding an Input Check Box in JavaScript

add input check box javascript

  • Please log in to reply
 

#1 SmartWeb

SmartWeb

    Senior Member

  • Designer
  • 271 posts

Posted 07 December 2012 - 02:21 AM

To add an input checkbox in JavaScript:
1.Using Notepad, or any HTML editor create a new HTML document. Then add the following HTML headers to the file:
<!DOCTYPE HTML>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Adding a Check Box</title>
</head>
2.Now create an HTML form with a name inside your document’s body. Also add a list box to select Yes or No. Then use the onChange event to call a JavaScript function when the selection changes.
<body>
<form name="Form1">
<select name="yesno" onChange="checkit();">
<option>Select</option>
<option>Yes</option>
<option>No</option>
</select>
3.Insert JavaScript tag <script> before the closing </head>
<script>
var hasBox = false;
4.Create the function that should be called when the selection changes.
function checkit() {
var selection = document.myForm.yesno.selectedIndex;
var selectionText= document.myForm.yesno[selection].text;
5.Add an input check box to the form . Also use the method "createElement" to create a new element.
if (selecText == "Yes" && !hasBox) {
var box = document.createElement("div");
box.innerHTML = '<input type="chkbox" name="checkme"> Check here ';
document.myForm.appendChild(box);
hasBox = true;
}
</script>





Also tagged with one or more of these keywords: add input check box, javascript

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users