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 6579731
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:56:05+00:00 2026-05-25T15:56:05+00:00

This is my html form I am using. <label>Your Username:</label><input id=username name=username type=text onchange=return

  • 0

This is my html form I am using.

<label>Your Username:</label><input id="username" name="username" type="text" onchange="return ajax ('username');" />

This is my ajax checking file in php.

if ($_REQUEST['username']) {

$q = $dbc -> prepare("SELECT username FROM accounts WHERE username = ?");
$q -> execute(array($_REQUEST['username']));

if (strlen($_REQUEST['username']) < 3) {
    echo '<div class="error">Has to be at least 3 characters</div>';
}   

elseif ($q -> rowCount() > 0) {
    echo '<div class="error">Username already taken</div>';
}
else {
    echo '<div class="success">Username available</div>';
}
}

And my jquery ajax request…

function ajax (input) {

var val = $('#'+input).val();
$('.loading').fadeIn().delay(100);
$.post("ajax.php", {
    username: val,
}, 
function (response) {
    $('.error, .success').hide();
    setTimeout(function(){
        $('.loading').hide();
            finishAjax(input, response);
    }, 1000);
});
return false;
}

function finishAjax(id, response) {

$('#'+id).after(response).fadeIn(2000);
}

On my form I call the ajax request with the variable username.

In my ajax.php the correct validation of the username takes place if the request is named username.

I would like to display the variable input in place of username in the jquery code so I can use this script for other validations and pass the variable as email, or password and the script will still run as the value of input will be what it needs to be.

If that makes sense.

Thanks for your time.

  • 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-25T15:56:06+00:00Added an answer on May 25, 2026 at 3:56 pm
    var data = {};
    data[input] = $('#' + input).val();
    
    $.post("ajax.php", data, function() {...
    

    and

    finishAjax(input, response);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this HTML dropdown: <form> <input type=text id=realtxt onkeyup=searchSel()> <select id=select name=basic-combo size=1>
i have this html <ul> <li><form action=# name=formName></li> <li><input type=text name=someName /></li> <li><input type=text
I am creating a select box for a form using this in _form.html.erb <%=
This piece of valid json (it has been generated using php's json_encode): {html:form is
Using jQuery/jQueryUI I want to populate a form using this HTML/JS show below. The
I have this html form which has options: <tr> <td width=30 height=35><font size=3>*List:</td> <td
How can I the HTML string <br> from this HTML FORM pass to the
When I create a html form like this: $form = new Zend_Form(); $form->setMethod('post'); $form2->addElement('textarea',
I have a html form with the data by this post method 'form id='form1'
I am trying to use an HTML form and javascript (i mention this, because

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.