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


Validating a check box in HTML

html validating check box

  • Please log in to reply
&nsbp;

#1 DesGuru

DesGuru

    Senior Member

  • Designer
  • 220 posts

Posted 07 August 2013 - 11:52 PM

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.

#2 pandor

pandor

    Member

  • Designer
  • 59 posts

Posted 19 August 2013 - 08:11 PM

Interesting script I have to try it ;)

#3 GJR

GJR

    Moderator

  • Designer
  • 2637 posts

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.

Edited by GJR, 20 August 2013 - 08:28 AM.






Also tagged with one or more of these keywords: html, validating check box

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users