Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1133
  • Last Modified:

jquery tool tip form validation using remote

I am attempting to use this jquery script to validate a form. (code snippet 1)

It works fine, but i would like to include a remote: check for username  (code snippet 2)

is there a way to incorporate the 2? or someway of getting the desired results?

I just don't know javascript well enough to figure this out.




/* snippet 1 */

<script language="javascript" type="text/javascript">
        $(document).ready(function() {
            // Setting up the suggestion box
            $("#txtFullName").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ehi, it looks good!",
                // Text displayed when the input doesn't pass the validation
                badText: "Ouch, it looks empty!",
                // Text displayed as a tip when the input field is focused
                tipText: "Here, just input something",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                    // Checking if the input field contains text.
                    if (inputValue.length > 0) callback(1);
                    else callback(0);
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });

            // Setting up the suggestion box
            $("#txtEmail").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ehi, nice email!",
                // Text displayed when the input doesn't pass the validation
                badText: "Ouch, it doesn't look like an email!",
                // Text displayed as a tip when the input field is focused
                tipText: "Type an email address",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                // Checking if the input field contains text.
                    var emailRegexp = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
                    if (emailRegexp.test(inputValue)) callback(1);
                    else callback(0);
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });
        });
    </script>



/* Snippet 2 */

$(\"#txtUserName\").validate({
				rules: {

					username: {
						required: true,
						minlength: 2
						remote: \"remote_check.php\"
						}
            		},
            		
            		messages: {
            		  username: {
            			minlength: \"Your username must consist of at least 2 characters\"
            			remote: \"Your username is already taken\"
            				}
            			}

            
            }
            );

Open in new window

0
lexshine
Asked:
lexshine
  • 2
1 Solution
 
HaloWebProjectsCommented:
try this, i have only modified the second box, the email
// Setting up the suggestion box
            $("#txtEmail").inputTip({
                // Text displayed when the input passes the validation
                goodText: "Ehi, nice email!",
                // Text displayed when the input doesn't pass the validation
                badText: "Ouch, it doesn't look like an email!",
                // Text displayed as a tip when the input field is focused
                tipText: "Type an email address",
                /* Function called to validate the input. It should fire "callback" with the following parameters
                *  First parameter:
                *  - 0: validation failed
                *  - 1: validation succeeded
                *  - 2: show the tip text
                * Second parameter: optional text to display instead of the standard text */
                validateText: function(inputValue, callback) {
                // Checking if the input field contains text.
                    
					if ($(this).validate({
						rules: {
							username: {
							required: true,
							minlength: 2
							remote: "remote_check.php"
							}
            			},
	            		messages: {
    		        		username: {
            					minlength: "Your username must consist of at least 2 characters"
            					remote: "Your username is already taken"
            				}
            			}
		            }))	 callback(1);
		            else callback(0);
                },
                // True if the validation should be performed on every key/up event (false by default)
                validateInRealTime: false
            });

Open in new window

0
 
lexshineAuthor Commented:
I entered this as u have it and it doesn't work. It also breaks the existing scripts functionality.
0
 
lexshineAuthor Commented:

I have made this work by scrapping the validation functions and writing my own within the structure of the initial jquery code..
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now