Page 2 of 2 First 12
  • Jump to page:
    #16
  1. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,963
    Rep Power
    4035
    Try using something like this and check the URL for the image to see if it has the ?n=1. If it does, it should be the inital load and you shouldn't do anything.

    Code:
    function response(src, exists){
      if (src.indexOf('?n=1')==-1){
        //This is not the inital load, so the submit button was probably clicked.
        if (exists){
          alert('That username is taken, please choose another');
        }
        else {
          document.formName.submit();
        }
      }
    }
  2. #17
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2002
    Posts
    292
    Rep Power
    0
    Hmmm that caused the submit button to do nothing when clicked... I tried a few more things with that concept with the same problem.


    Is there some basic javascript to see if a submit button was clicked?

    My other logistical nightmare going this route is upon update, if the username is the same, then of course it exists. But I still need to do a check if there is an existing username in case they change that field. Is there a way to incorporate an onChange into this mess?

    So, if onChange(username) then run the existing user check, else move along because the username didn't change. Would something like that work? If so, how?

  4. #18
  5. Wiser? Not exactly.
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    May 2001
    Location
    Bonita Springs, FL
    Posts
    5,963
    Rep Power
    4035
    I suppose an easier way would be to setup a couple of flags, then use those to check whether or not you need to submit/check the username. Here is a sample page just to check if a name exists.

    Code:
    <html>
     <head>
      <title>Check Username</title>
      <script type="text/javascript">
      var changed=false, check=false;
      function checkName(frm){
        if (window.changed==true){
          document.checkimg.src='response.php?u='+escape(frm.uname.value);
          window.check=true;
          window.changed=false;
        }
        else {
          alert('Username has not been changed');
        }
      }
      function response(exists){
        if (window.check){
          if (exists){
            alert('Username exists');
          }
          else {
            alert('Username doesn't exist');
            document.checker.submit();
          }
      }
      </script>
     </head>
     <body>
      <form method="post" action="handler.php" name="checker">
      <input type="text" value="" name="uname" onchange="window.changed=true;"> Username<br>
      <input type="submit" value="Check it" onclick="checkName(this);return false;">
      </form>
      <img name="checkimg" src="response.php?n=1" onload="response(true);" onerror="response(false);" width="1" height="1">
     </body>
    </html>
Page 2 of 2 First 12
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo