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!

js form name 1

Status
Not open for further replies.

cfusionit

Programmer
Dec 22, 2004
2
US
i am validating an input field and would like to clear the field if the user typed an invalid character.


function validateTotal(thevalue){
if(thevalue.length >= 1)
{
if (isNaN(thevalue) || thevalue <= 0) {
alert(thevalue + ' is not a valid number!');
}
}
}

-- my field names are dynamic. how do i reference this in the "validateTotal" function so i can clear the field?

<input type="Text" name="xyz#t#" size="10" value="#form.regiontotal#" onkeyup="validateTotal(this.value);">

thanks

ryan
 
Instead of calling validateTotal(this.value), call validateTotal(this).
Then:
Code:
function validateTotal(f)
{
  var thevalue = f.value;
  if(thevalue.length >= 1)    
  {
    if (isNaN(thevalue) || parseInt(thevalue) <= 0)
    {
      alert(thevalue + ' is not a valid number!');           
      f.value = "";
    }
  }
}

--Chessbot

There is a level of Hell reserved for probability theorists in which every monkey that types on a typewriter produces a Shakespearean sonnet.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top