Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

validate numeric

Status
Not open for further replies.

ixnay5

MIS
Jan 10, 2002
68
US
hi -

trying to simply validate a text box entry (fieldname: qty) on form submit. if it's not numeric, throw an alert. but of course it isn't working and i can't see why. it's throwing the alert whether the entry is valid or not.

here's the code: (ignore pcount and scount...they're always correctly filled by other means)

Code:
function isblank(s) {

	for(var i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if ((c != ' ') && (c != '\n') && (c != '')) return false;
		
	}

	return true;

}

function validate(f) {

	var msg1 = "Message!"
	var q = parseInt(f.qty.value);

	if ( (f.pcount.value == "") || (f.scount.value == "") || (isblank(q)) ||  (isNAN(q)) ){

		alert(msg1);
		return false;
	}
	
	return true;
}
 
Try this:

Code:
function validate() {
    if (isNaN(document.frmpage.start_date.value)) {
        alert("Not a number!");
    } else {
        alert("Is a number!");
    }
}

HTH

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 
well for one thing, "(isblank(q))" makes no sense. still trying...
 
i just pulled the isNAN(q) from the function and put this:

Code:
function tst_qty(fieldobj)  {
	
	
	//if the value entered isn't acceptable, bail out
	var v = parseFloat(fieldobj.value);
	if (isNaN(v)) {
		errors = "Please enter a number";
		alert(errors);
		return false;
	}
	return true;
}

as an onchange() in the text box itself.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top