Hi,

I've got a strange issue on my hands here. I'm trying to get AJAX form validation working for a user registration form for a project I'm working on. I have it working in all fields except the username field.

Here's the JS code that it calls from the form.

Code:
if (id == "username") {
                var unInp = document.getElementById('username').value;
                if (unInp.length > 4) {
                    // send input to validator file
                    $.get("../includes/validator.php", { check: "true", type: "username", value: unInp },
                            function(data) {
                                if (data == "0") {
                                    document.getElementById(id + 'IMG').src = "images/tick.png";
                                    $('#form_hidden').fadeIn(400);
                                } else {
                                    document.getElementById(id + 'IMG').src = "images/cross.png";
                                }
                            });

                } else {
                    document.getElementById(id + 'IMG').src = "images/cross.png";
                }
            }
It seemingly skips over the "if (id == "username") {" and automatically displays the 'else' which is the cross.png meaning it's wrong.

Here's the code from the page where the form is:

Code:
<form method='post' action='register.php' id='wcwlogin' class='dropout'>

                	<label class='login' for='username'>"?><? echo outputLan('regPage','username'); ?></label>
                	<input type="text" autocomplete="off" name="username" id="username" class="input_field" size="40"
                        onkeyup="checkInput('username');" value="<? echo $username;?>" /> <? echo "<img id='usernameIMG'
                                                                                               src='images/loader.gif'
                                                                                               alt='output'
                                                                                               class='hidden'>

                <div id='form_hidden'>
                    <label class='login' for='firstname'>"?><? echo outputLan('regPage','first name');?><? echo "</label> 
                    <input type='text' autocomplete='off' name='firstname' id='firstname' class='input_field' size='47'
                           "?> onkeyup="checkInput('firstname');" value="<? echo $fname;?>"><? echo "<img id='firstnameIMG'
                                                                                                 src='images/loader.gif'
                                                                                                 alt='output'
                                                                                                 class='hidden'>

                    <label class='login' for='lastname'>"?><? echo outputLan('regPage','last name');?><? echo "</label>
                    <input type='text' autocomplete='off' name='lastname' id='lastname' class='input_field' size='47'
                           "?> onkeyup="checkInput('lastname');" value="<? echo $lname;?>"> <? echo "<img id='lastnameIMG'
                                                                                                src='images/loader.gif'
                                                                                                alt='output'
                                                                                                class='hidden'>

                    <label class='login' for='email'>"?><? echo outputLan('regPage','email');?><? echo "</label>
                    <input type='text' autocomplete='off' name='email' id='email' class='input_field' size='47'
                          "?> onkeyup="checkInput('email');" value="<? echo $email;?>" <? echo "<img id='emailIMG'
                                                                                             src='images/loader.gif'
                                                                                             alt='output'
                                                                                             class='hidden'>
                    <label class='login' for='password'>"?><? echo outputLan('regPage','password');?><? echo "</label>
                    <input type='password' autocomplete='off' name='password' id='password' class='input_field' size='47'
                           "?> onkeyup="checkInput('password');" value="<? echo $pass;?>" <? echo "<img id='passwordIMG'
                                                                                               src='images/loader.gif'
                                                                                               alt='output'
                                                                                               class='hidden'>
                    <label class='login' for='password2'>"?><? echo outputLan('regPage','password2');?><? echo "</label>
                    <input type='password' autocomplete='off' name='password2' id='password2' class='input_field' size='47'
                           "?> onkeyup="checkInput('password2');" value="<? echo $pass2;?>"<? echo "><img id='password2IMG'
                                                                                                 src='images/loader.gif'
                                                                                                 alt='output'
                                                                                                 class='hidden'>"?>

                    <label class='login' for='gender'><? echo outputLan('regPage','gender');?><? echo "</label>
                    <select name='gender' style='padding:25px;' id='gender' class='input_field' style='height:30px;'>
                        "?> <option value="select" <? echo "$dSel;"?>><? echo "Select</option>
                        "?><option value="male" <? echo "$mSel;"?>><? echo outputLan('regPage','male');?></option>
                        <option value="female" <? echo "$fSel;"?>><? echo outputLan('regPage','female');?></option>
                    </select>
		
		<label class='login' for='contact'><? echo outputLan('regPage','contact');?><? echo "</label>
		<select name='contact' id='contact' class='input_field' style='height:30px;'>
			<option value='yes'>Yes</option>
			<option value='no'>No</option>
		</select>

                    "?><input type='hidden' name='cap1' id='cap1' value="<? echo $cap1; ?>">
                       <input type='hidden' name='cap2' id='cap2' value="<? echo $cap2;?>"> <? echo "

                    <label class='login' for='captcha'> "?><? echo outputLan('regPage','captcha'); echo $capString;?><? echo "</label>
                    <input type='text' autocomplete='off' name='captcha' id='captcha' class='input_field' size='10'
                           "?> onkeyup="checkInput('captcha');"<? echo "><img id='captchaIMG' src='images/loader.gif' alt='output'
                                                                 class='hidden'>
                    <br/>
                    <input type='submit' name='register' id='subBut' "?> value="<? echo outputLan('regPage','register button');?>"<? echo "class='submit'>
                </div>
                <!-- end of hidden form element -->
            </form>
    </div> </div>";
}

?>
That is only part of the code on the page....that's just the form.

The weird thing is that every other form element is working and validating itself properly.....even the email field which has a very similar validation process when compared to the username field. Both have to query the database to see if the value is already present. But the username field doesn't seem to even be getting that far.

Any help would be greatly appreciated. If you need more of the code, please let me know.

Thank you!!