[Javascript] (no subject)
Hassan Schroeder
hassan at webtuitive.com
Wed Nov 2 10:03:44 CST 2005
Scott Hamm wrote:
> Hi all. I'm new to this mailing list and I'm ASP/SQL application
> developer. I've been using SQL stored procedure to do error
> corrections until I realize that it created high traffic between ASP
> and SQL so I decided to learn javascript.
>
> What I need for my web to do is to ensure that khrs have '0' or more
> and is numeric and/or if kpto is more than '0' and is numeric AND sum
> of khrs and kpto MUST not exceed 8 hours. I do not want both kph and
> kpto to have '0' values at same time either. So I created this
> script, everything works up to kph+kpto and I've been struggling to
> figure out why.
> function validateKronos()
> {
> digits="0123456789."
> if(krono_process.assocID.options[0].selected)
> {
> alert("Associate is not selected")
> krono_process.assocID.focus()
> return false;
> }
> else
> {
> var kph=krono_process.khrs.value
> len=kph.length
> if(len==0)
> {
> alert("Hours is not indicated. Enter 0 if no hours worked.")
> krono_process.khrs.focus()
> return false;
> }
> else
> {
/* not related to your original question, but you can skip this loop
* thing altogether with isNan (Not A Number)...
*/
> for(i=0;i<len;i++)
> {
> if(digits.indexOf(kph.charAt(i))<0)
if ( isNan(kph) )
> {
> alert("Hours must be numeric")
> krono_process.khrs.focus()
> return false;
> }
> }
> var kpp=krono_process.kpto.value
> len=kpp.length
> if(len!=0)
> {
> for(i=0;i<len;i++)
> {
> if(digits.indexOf(kpp.charAt(i))<0)
> {
> alert("PTO must be numeric")
> krono_process.kpto.focus()
> return false;
> }
> }
/* You're trying to add two values which at that point are strings,
* and the + operator can apply to either strings or numbers, so...
* untested, but from memory of previous encounters :-)
*/
var kptot = (krono_process.kpto.value + 0);
var khtot = (krono_process.khrs.value + 0);
/* or force type conversion by: */
var kptot = Number(krono_process.kpto.value);
var khtot = Number(krono_process.khrs.value);
> ktot=kpp+kph
> If(ktot>8)
HTH!
--
Hassan Schroeder ----------------------------- hassan at webtuitive.com
Webtuitive Design === (+1) 408-938-0567 === http://webtuitive.com
dream. code.
More information about the Javascript
mailing list