LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 10-19-2005, 05:00 AM   #1
rblampain
Member
 
Registered: Aug 2004
Location: Western Australia
Distribution: Debian 7
Posts: 833

Rep: Reputation: 35
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>

Last edited by rblampain; 10-19-2005 at 05:20 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Debian, KDE, sporadic disk access mbeattie74 Linux - Hardware 0 11-17-2005 07:24 PM
sporadic mouse hang/crashes darkmatter333 Slackware 6 11-27-2004 11:07 PM
sporadic network problems on direct connection pfunk Linux - Networking 0 10-14-2004 03:09 PM
network sporadic and slow IF it starts artao Linux - Networking 13 02-27-2004 12:49 AM
Java/Javascript problem????? Jadewolf Linux - Software 2 10-25-2003 07:06 PM


All times are GMT -5. The time now is 01:14 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration