?
Solved

jquery tool tip form validation using remote

Posted on 2010-01-10
3
Medium Priority
?
1,130 Views
Last Modified: 2012-05-08
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
Comment
Question by:lexshine
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 2

Expert Comment

by:HaloWebProjects
ID: 26289898
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
 

Author Comment

by:lexshine
ID: 26290061
I entered this as u have it and it doesn't work. It also breaks the existing scripts functionality.
0
 

Accepted Solution

by:
lexshine earned 0 total points
ID: 26291995

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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question