If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 1 of 1
  1. #1
    Senior Member shoffman3572's Avatar
    Join Date
    Jul 2008
    Fullerton, CA
    Member #
    I'm building a form, that asks the user to select a nickname to use. That nickname has to be one of a kind so I do a quick check against the mysql table that stores user accounts to make sure the nickname they select is ok to use.
    so here's the form element:
    <input id="nick" name="nick" type="text" size="15" maxlength="20" onChange="getNickname()" class="searchBox">
    which 'onChange' calls this function:
    function getNickname()
    var name = document.getElementById('nick').value;
    if (name.length < 4 || name == "" )
    { alert("Please Enter a nickname - Between 4 and 20 letters please.");
    return false; }
    var myURL = "getNickname.php?nick=" + name + "";"POST", myURL, true);
    http.onreadystatechange = useHttpResponce;
    this calls 'getNickname.php'
    <? include("dbConnect.php");
    $getNickname = mysql_query("SELECT A.nickname, B.nickname FROM dancers A, voter B WHERE A.nickname='$nick' OR B.nickname='$nick'");
    $result = mysql_num_rows($getNickname);
    if ($result >0)
    echo ("That nickname is already in use. Please try another.");
    echo ("OK!");
    } ?>
    the result of the query is then sent to:
    function useHttpResponce()

    if (http.readyState == 4)
    if (http.status == 200)
    var nickname = http.responseText;

    document.getElementById('nicknameError').innerHTML = "<b>" + nickname + "</b>";
    if (http.responseText != "OK!")
    document.getElementById('nick').value = "";
    document.getElementById('nicknameError').innerHTML = "<b>!</b>";
    The problem i can't figure out is - if the nickname is NOT OK - I want to text field to clear to so stop the user accidentally submitting a nickname that is already in use - so I check to see if the responseText is not = "OK!" - if the nickname is NOT ok, then clear the box - this part is working but even if the responseText is = "OK!" meaning the nickname is ok to use - it still clears the text field, making it impossible for a user to enter anything!
    any ideas as to what I'm doing wrong here?


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
All times are GMT -6. The time now is 01:11 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2020 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: