Forum Moderators: open
function validatedeproc(form)
{
if(form.elements.DE_Cat.options[0].selected)
{
alert("Category is not selected")
form.elements.DE_Cat.focus()
return false;
}
var dqty=form.elements.deqty.value
var dhrs=form.elements.dehrs.value
dqlen=dqty.length
dhlen=dhrs.length
dqty=parseFloat(dqty)
dhrs=parseFloat(dhrs)
if(dqlen==0)
{
alert("Must indicate qty, if nothing, use 0.")
form.elements.deqty.focus()
return false;
}
else
{
if(isNaN(dqty))
{
alert("QTY must be numeric")
form.elements.deqty.focus()
return false;
}
}
if(dhlen==0)
{
alert("No hours entered, please enter hours.")
form.elements.dehrs.focus()
return false;
}
else
{
if(isNaN(dhrs))
{
alert("Hours must be numeric")
form.elements.dehrs.focus()
return false;
}
}
}
If you do this:
var n = parseFloat("1.a");
The result is that n equals 1
If you do this:
var n = parseFloat("1.01");
The result is that n equals 1.01
If you remove the parseFloat() call, then your test for isNaN will check against the full value entered (1.a), which will behave the way you want it to.
Hope that helps.
According to devguru.com, the parseFloat() function determines if the first character in the string argument is a number, parses the string from left to right until it reaches the end of the number, discards any characters that occur after the end of the number, and finally returns the number as a number (not as a string).
This means that if '1.a' is passed to parseFloat(), it will return 1 as a number, discarding the rest of the string.
Why do we need parseFloat?
You still need parseFloat() to turn a string of numerals into a number--like if you had a number that you wanted to extract from the middle of a string.
ajkimoto