Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5970001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T20:18:43+00:00 2026-05-22T20:18:43+00:00

For some reason, I cannot figure out how to return the value of an

  • 0

For some reason, I cannot figure out how to return the value of an input after I’ve typed something into it. This is in relation to this problem and I’m not able to validate anything without the username value being recognized. I’m running jQuery 1.6.1 and Validate 1.8.1.

Here’s the form HTML:

<form class="cmxform" action="register.php" method="post" name="signup" id="signup">
   <ul>
      <li>
        <label for="username">Username: <em>*</em></label>
        <input type="text" id="username" name="Username" size="20" class="required" placeholder="Username" />
      </li>
   </ul>
</form>

Before submitting the form, I want to make sure I can see the value of the username I type into the input. I have an alert that returns the value of the username, but the alert always shows nothing. Here’s the JS code I’m using:

$(document).ready(function(){

var username = $("#username").val();
var parameter = "action=checkusername&username="+username;

$.validator.addMethod("checkAvailability",function(value,element){
    $.ajax({
          url: "dbquery.php",
          type: "POST",
          async: false,
          data: parameter,
          success: function(output) {
                     alert (username);
                     return true;
         }
     });
},"Sorry, this user name is not available");

// jQuery Validation script
    $("#signup").validate( {
        rules: {
            Username: {
                required: true,
                minlength: 5,
                checkAvailability: true // remote check for duplicate username
                }
            }
        },
        messages: {
            Username: {
                required: "Enter a username"
            }
        },
        submitHandler: function(form) {
            form.submit();
        }
    });

Should I be using something other than val() to get the value of the username? I’m so confused why it’s not giving me the value that I need!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T20:18:43+00:00Added an answer on May 22, 2026 at 8:18 pm

    you are hard coding username at the beginning of your javascript. do it inside the addMethod success call

    $.validator.addMethod("checkAvailability",function(value,element){
      var nameAvailable = false;
      $.ajax({
          url: "dbquery.php",
          type: "POST",
          async: false,
          data: "action=checkusername&username="+value,
          success: function(output) {
            //server returns whether username is valid or not
            //if it is valid set nameAvailable to true like so:
            nameAvailable = true;
          }
      });
    
      return nameAvailable;
    
    });
    
    $("#signup").validate({
      username: {
        required: true,
        checkAvailability: true
      },
      messages: {
        username: {
          required: "Username is required",
          checkAvailability: "Sorry, this user name is not available"
        }
      },
      submitHandler: function(form) {
        form.submit();
      }
    });
    

    HTML

    <input type="text" id="username" name="username" size="20" class="required checkAvailability" placeholder="Username" />
    

    putting it where you have it now means that when the page loads it immediately grabs the value in the username text field, which will be empty.

    EDIT:

    changed the code a little to work correctly

    EDIT: jsfiddle of above code

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason or another I cannot figure out why the data when opened
It's a common problem, solved many times, but for some reason i cannot find
This is kind of embarrassing but I cannot for some reason get his CSS
For some reason this PHP code below will not work, I can not figure
I cannot figure this out! I am trying to get a list of a
I have been trying to figure this problem out without asking for help, but
for some reason I cannot see any of the generated objects under the TL
For some reason I cannot seem to get a ko.computed observable to compute when
For some reason the selected tab on TextMate is almost un-noticeable, I really cannot
For some reason, no matter how I go about it, I cannot get TortoiseSVN

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.