Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to make form text input value compare against list of already obtained values?

    I'm a newbie to JS.

    What i want to do is check the value of an input text field (onChange) and compare it with a list of values already grabbed from a DB (these will be text names). If it the text is not any of those values, i want a popup box to appear. I know how to do the popup box text, but am stumped by the rest of it. Any ideas? thanks.
    Last edited by Neophyte; 08-05-2002 at 07:10 AM.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    i think it's better to use onblur event instead of onchange, because you can't force user to change the value of the textbox if onchange is used.

    var arrNames = ("text1","text2","text3"...); //values from db

    function checkName(objTxt){
    var found=false;
    for (var i=0;i<arrNames.length;i++){
    if (objTxt.value==arrNames[i]){
    found=true;
    break;
    }
    }
    if (!found){
    alert("'"+objTxt.value+"' not found.");
    objTxt.focus();
    return false;
    }
    return true;
    }

    then in your html:
    <input name="text" value="somevalue" onblur="return checkName(this)">
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Aug 2002
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hey, thanks! i'm at work so i can't try it right now but i will when i get home. much appreciated!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •