Original:
Expand|Select|Wrap|Line Numbers
- $("#checkUname").click(function(){
- var datastring= $('form#newUserForm').serialize();
- $.ajax({
- type: "POST",
- url: "index.cfm?event=user.checkUname&requestFormat=ajax",
- data: datastring,
- success: function(response){
- var resp = jQuery.trim(response);
- if (resp == 'FALSE'){
- $('.toggleSuccess').show();
- $('.toggleFailure').hide();
- }else{
- $('.toggleFailure').show();
- $('.toggleSuccess').hide();
- }
- }
- });// .ajax()
- return false;
- }); // .submit()
Field I wish to validate:
Expand|Select|Wrap|Line Numbers
- <input class="text required" name="uname" type="text" />
Expand|Select|Wrap|Line Numbers
- <input name="submit" type="submit" onclick="checkuname()" />
Expand|Select|Wrap|Line Numbers
- function checkuname(){
- var datastring = document.getElementById('uname');
- $.ajax({
- type: "POST",
- url: "index.cfm?event=user.checkUname&requestFormat=ajax",
- data: datastring,
- success: function(response){
- var resp = jQuery.trim(response);
- if (resp == 'FALSE'){
- return true;
- }else{
- $('.toggleFailure').show();
- $('.toggleSuccess').hide();
- return false;
- }
- }
- });// .ajax()
- };
I should note (in case it might be relevant) that before this function in the JS file, I have a call to the JQuery validate plugin which I call like so:
Expand|Select|Wrap|Line Numbers
- $('form#newUserForm').validate();