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

  • SEARCH
  • Home
  • 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 3347326
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:24:30+00:00 2026-05-18T01:24:30+00:00

I have an input field which I would like to dynamically validate while user

  • 0

I have an input field which I would like to dynamically validate while user is typing… I am using Codeigniter and I believe that I have some URI problem… Let me show you the code…

HTML/PHP:
<input type="text" id="username"> <span id="validateUsername"></span>

jQuery:

$(document).ready(function() {
    var validateUsername = $('#validateUsername');
        $('#username').keyup(function () {
        var t = this; 

        if (this.value != this.lastValue) {
            if (this.timer) clearTimeout(this.timer);
            validateUsername.removeClass('error').html('<img src="<?php echo site_url("public/images"); ?>/ajax-loader.gif" height="16" width="16" /> checking availability...');
            this.timer = setTimeout(function () {
                $.ajax({
                    url: '<?php echo base_url(); ?>register/check_user/' + t.value,
                    dataType: 'json',
                    type: 'POST',
                    success: function (j) {
                        validateUsername.html(j.msg);
                    }
                });
            }, 200);

            this.lastValue = this.value;
        }
    });
});

My codeigniter controller has a very simple function:

function check_user($username) {
    // var_dumping stuff goes here
}

In there I’m just trying to var_dump different stuff (like $_SERVER, $_REQUEST, $username), but I think that my script doesn’t even reach that controller…

I was trying to change url: '<?php echo base_url(); ?>register/check_user/' + t.value, line in my jQuery script but it seems that no combination works. For example:
url: '<?php echo site_url('register/check_user/'); ?>' + t.value,
url: 'index.php/register/check_user/' + t.value,
url: 'register/check_user/' + t.value,

…whatever I try my validateUsername span shows only “checking availability” message.

I was trying my script in Chrome, Safari and IE8. PHP version is 5.3.0 and jQuery is 1.4.2…

Any ideas what could be wrong here?

Thanks for any help in advance!

  • 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-18T01:24:31+00:00Added an answer on May 18, 2026 at 1:24 am

    I see there could be multiple issues with your code:

    are the routes properly set?

    In your CodeIgniter routes, do the following:

    $route['register/check_user/(:any)'] =" register/check_user/$1";
    

    In your CodeIgniter controller, access the variable using this:

    function check_user() {
        $username = $this->uri->segment(3);
        var_dump($username);
        // var_dumping stuff goes here
    }
    

    Also, I would suggest using jQuery Text Change event, It has worked great for me, instead of using setTimeouts and keyup.

    Example:

    $('#username').bind('textchange', function () {
       $.post('<?php echo base_url(); ?>register/check_user/' + this.value, function(data) {
          $('#validateUsername').html(data);
        });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a dynamically generated form that I would like to submit using Ajax.
I have got two input fields which i would like to make editable with
I have created a add input field function which is working fine. I would
i have an input field which will be displayed. i want that to hide
I have a form with input field which can be accessed like var algorithm
I have a form input field that accepts multiple tags from a user, a
I have a form which is dynamically generated based on user input. Initially the
I would like to perform form validation using JavaScript to check for input field
I would like to select the text of the input field which currently has
I have an input field which has a placeholder text. I want one word

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.