1.Open your HTML page in any text editor.
2. in the head section insert the following:
<script type="text/javascript" language=javascript>
function chkCheckBoxes() {
if (document.frmTest.CHKBOXA.checked == false &&
document.frmTest.CHKBOXB.checked == false &&)
{
alert (Put your message here!');
return false;
}
else
{
return true;
}
}
</script>
3.Scroll down to your HTML body, where the check box code is
4.Add the below code to the check box code:
<form onsubmit="return chkCheckBoxes();" action="" name="frmTest">
...
</form>
4.Save your HTML.
Validating a check box in HTML
1.Open your HTML page in any text editor.
2. in the head section insert the following:
<script...
html validating check box
&nsbp;
#3
Posted 20 August 2013 - 08:11 AM
I would do it like this - or use a library like jquery.
more efficient and less error prone as changes to the form object could cause it to fail. you could move the checkbox to another form and it would still work.
modified the code:
function chkCheckBoxes(){
var chkbox = document.getElementById('chkboxa');
if (!chkbox.checked)
{
alert ("Put your message here!");
return false;
}
return true;
}
html is the same.
more efficient and less error prone as changes to the form object could cause it to fail. you could move the checkbox to another form and it would still work.
modified the code:
function chkCheckBoxes(){
var chkbox = document.getElementById('chkboxa');
if (!chkbox.checked)
{
alert ("Put your message here!");
return false;
}
return true;
}
html is the same.
Edited by GJR, 20 August 2013 - 08:28 AM.
Also tagged with one or more of these keywords: html, validating check box
Web Design →
CSS / HTML →
What files do I have to upload if I win a contest: vector or html?Started by webdev01, 06 Dec 2015 html, contest |
|
|
||
Web Design →
CSS / HTML →
Creating a moving navigation bar in HTMLStarted by OneDes, 11 Dec 2012 html, moving navigation bar |
|
|
||
Web Design →
CSS / HTML →
Converting a Word Documents to HTMLStarted by SmartWeb, 04 Dec 2012 converting word documents, html |
|
|
||
Web Design →
CSS / HTML →
Using HTML With JoomlaStarted by SmartWeb, 04 Dec 2012 html, joomla |
|
|
||
Web Design →
CSS / HTML →
Making text blink in HTMLStarted by SmartWeb, 04 Dec 2012 blinking, html, text |
|
|
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users