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 John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Salary and Numeric form validation: Javascript

Status
Not open for further replies.

BionicJacks

Programmer
Dec 6, 2001
3
CA
I am wanting to create a form to validate a salary number entered into the text box, so it contains a valid, non-negative currency. How would I go about this? Please help me.
 
if(!isNaN(yourValue) && yourValue >= 0) {
return true;
} else {
return false;
}

would return true is yourValue was a number greater then 0.
 
Could you explain this a little more to me, please. I don't know if I explain myself correctly, and I am somewhat confused. This text box is blank and the user will enter a salary number, when the user presses the 'apply changes' button, this form will then be validated. If nothing entered into the text box the user is prompted to enter something in with numerical value. Sorry, this stuff confuses me.
 
ok that i can do.

in the head of your page put this...

<script>
function checkSalary(obj) {
if(!isNaN(obj.salary.value) && obj.salary.value >= 0 && obj.salary.value.length > 0) {
return true;
} else {
alert(&quot;you must enter a valid salary&quot;)
return false;
}
}
</script>


and your form tag should have this: onSubmit=&quot;return checkSalary(this)&quot;

and your text box the user puts the salary in should be called &quot;salary&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top