


The Javascript functions below are common form validation techniques. Take a look. Copy and paste these functions into your own pages as you need them. The previous page shows how they get called in the HTML document.
<SCRIPT LANGUAGE="javascript">
function noEntry(){
input_value=document.forum.largetext.value;
if (input_value.length<1){
alert("Please complete the required form field below.");
document.forum.largetext.focus();
}
}
function emailCheck() {
myvalue = document.forum.text1.value;
if ((myvalue.indexOf("@") >= 0) && (myvalue.indexOf(" ") < 0)) {
return true;
} else {
alert("Please enter a valid email address.");
return false;
}
}
function makeChoice() {
thevalue = document.forum.list1.selectedIndex;
if (thevalue == 0) {
alert("Please make a choice from the list");
return false;
} else {
return true;
}
}
function checkChecker() {
my_value = document.forum.drink.checked;
your_value = document.forum.live.checked;
if ((my_value == "0") && (your_value =="0")) {
alert("Milk does a body good!"
+"\r\r\r\r\r"+" -Sponsored by the National Dairy Council");
document.forum.drink.checked = "1";
}
}
</SCRIPT>
[Privacy Policy] [Terms of Use]

Home || The Math Library || Quick Reference || Search || Help

The Math Forum is a research and educational enterprise of the Drexel University School of Education.