LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Sporadic Javascript user problem. (https://www.linuxquestions.org/questions/programming-9/sporadic-javascript-user-problem-374590/)

rblampain 10-19-2005 05:00 AM

Sporadic Javascript user problem.
 
I'm a sporadic user of Javascript, when I have to do something with it I find I've got to re-learn everything. I've got the script below that I found on the net and adapted for my needs some time ago, it checks that there are values in a "form" and that some are valid values.

The "Submit" does submit without checking date elements if there is a value, (functions vda, vmt, vyr). The form calls
return function checkForm(this)
Could someone point me to the mistake or how to fix this?
Thank you very much for your help.
<script type='text/Javascript' language='javascript'>
<!--
var year=0;
function isEmpty(inputStr) {
if (inputStr == "" || inputStr == null) {
return true
}
return false
}

function inRange(inputStr, lo, hi) {
var num = parseInt(inputStr, 10)
if (num < lo || num > hi) {
return false
}
return true
}

function select(field) {
field.focus()
field.select()
}

function vnam(field) {
var input = field.value
if (isEmpty(input)) {
alert("This field is empty.")
select(field)
return false
}
return true
}

function vyr(field) {
var input = field.value
if (isEmpty(input)) {
alert("Please enter a year value.")
select(field)
return false
} else {
input = parseInt(field.value, 10)
if (isNaN(input)) {
alert("Please enter numbers only.")
select(field)
return false
} else {
var today = new Date()
var thisYear = today.getFullYear()
input = parseInt(field.value, 10)
if (isNaN(input)) {
alert("Please enter numbers only.")
select(field)
return false
} else {
if (!inRange(input,1,12)) {
alert("Please enter a month between 1 (January) and 12 (December).")
select(field)
return false
}}}
if (!bypassUpdate) {
}
return true
}

function vda(field) {
var input = field.value
if (isEmpty(input)) {
alert("Please enter a date value.")
select(field)
return false
} else {
input = parseInt(field.value, 10)
if (isNaN(input)) {
alert("Please enter numbers only.")
select(field)
return false
} else {
var monthField = document.fj4.mt
if (!vmt(monthField, true)) return false
var monthVal = parseInt(monthField.value, 10)
var monthMax = new Array(31,31,29,31,30,31,30,31,31,30,31,30,31)
var rmdr=year%4;
if (rmdr>0) monthMax[2] = 28;
var top = monthMax[monthVal]
if (!inRange(input,1,top)) {
alert("Please enter a day between 1 and " + top + ".")
select(field)
return false
}}}
return true
}

function checkForm(form) {
if (vnam(form.fn)) {
if (vnam(form.mn)) {
if (vnam(form.sn)) {
if (vnam(form.ad)) {
if (vnam(form.ct)) {
if (vyr(form.yr)) {
if (vmt(form.mt)) {
if (vda(form.da)) {
return true
}}}}}}}}
return false
}
//-->
</script>
</head>


All times are GMT -5. The time now is 09:30 AM.