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>
Adding an Input Check Box in JavaScript
To add an input checkbox in JavaScript:
1.Using Notepad, or any HTML editor create a new HTML document....
add input check box javascript
Also tagged with one or more of these keywords: add input check box, javascript
Web Design →
Javascript →
Comparing Strings in JavaScriptStarted by Salwa, 18 Jul 2013 ![]() |
|
![]() |
||
Web Design →
Javascript →
Using OnSubmit in JavaScriptStarted by Salwa, 18 Jul 2013 ![]() |
|
![]() |
||
Web Design →
Javascript →
Downloading Javascript to iPodStarted by OneDes, 13 Jun 2013 ![]() |
|
![]() |
||
Web Design →
Javascript →
Downloading JavaScript to BlackBerryStarted by OneDes, 13 Jun 2013 ![]() |
|
![]() |
||
Web Design →
Javascript →
Enabling JavaScript on a MacStarted by OneDes, 13 Jun 2013 ![]() |
|
![]() |
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users