• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

on checking validity of input. problem on my if-else.

 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello, i currently have an input element, which has an onklick function which would check for validity of input (accepting only a number or the values "min" or "max"). how do i do that? as of now, i could only check whether it is a number or not, but once i enter "max" or "min", they don't get accepted but they should be... how do i do that? thanks! this is my current code for the function:

function loopHandler(i)
{
if(isNaN(i.value) || i.value != "max" || i.value != "min")
{
alert ("Invalid input. Choose from any number, 'max' or 'min' ");
i.clear();
}
else
{
alert ("ok");
}

}

thanks thanks!
 
Ranch Hand
Posts: 62
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Christine,

Change your "if" to,

if( isNaN( i.value ) && i.value != "max" && i.value != "min" )
{
alert ("Invalid input. Choose from any number, 'max' or 'min' ");
//i.clear();
}
else
{
alert ("ok");
}

and also, what's this i.clear(), do you mean to clear the value ? If yes, use i.value = "";
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic