Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 2 of 2 FirstFirst 12
Results 16 to 23 of 23
  1. #16
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Quote Originally Posted by jackvan View Post
    It's exactly like this:

    url: "/cgi-bin/isaccount.cgi?username=jack",
    Sorry, but you don't get me

    Code:
    It's not exactly like this
    
    url: "/cgi-bin/isaccount.cgi?username=$name::getName()"
    which would involve a method execution instead of a simple variable name

  2. #17
    New Coder
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    I've just tested my script with your solutions:

    url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),

    or

    url:"/cgi-bin/isaccount.cgi",
    data : {username: name.val()},

    They don't work:

    1) url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),

    I entered: abcd in the name field of the Form,

    My Perl script, isaccount.cgi received two data: name.val() and usernameabcd immediately one after another??


    2) url:"/cgi-bin/isaccount.cgi",
    data : {username: name.val()},

    It did not send any data to isaccount.cgi and it also seems like it did not get into the success:function(data){ loop, i.e. it is not success.

    Any idea to fix it?

  3. #18
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Please show the full code of the ajax call and the corresponding form HTML

    I don't know about .cgi scripts, but in PHP the data would be available as $_GET["username"] or $_POST["username"] respectively depending on the type of request. Did you provide a type?

    Code:
    $.ajax({url: "...",
    type: "GET",
    data: {username: ...},
    ...
    });

  4. #19
    New Coder
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    Correction:

    The first method works with some a minor problem:

    url:"/cgi-bin/isaccount.cgi?username=" + encodeURIComponent(name.val()),

    When I entered: reggy

    I got: usernamereggy without an equal "=" between, i.e. I should be getting: username=reggy

    Any idea to fix it?

  5. #20
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    Obviously your .cgi is reading the values differently than usual. Try this
    Code:
    url:"/cgi-bin/isaccount.cgi?" + encodeURIComponent(name.val()),

  6. #21
    New Coder
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    No, I did not use type in the Ajax loop. That was the problem.

    After I insert: type: "GET", I'm getting proper data:

    username=john
    username=jack
    username=peggy

    etc

    Sorry for the confusion.

  7. #22
    New Coder
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    I've one other problem. Here's the code:

    PHP Code:
        //On blur
        
    name.blur(validateName);
        
    email.blur(validateEmail);
        
    pass1.blur(validatePass1);
        
    pass2.blur(validatePass2);
        
    //On key press
        
    name.keyup(validateName);
        
    name.keyup(validateName);
        
    pass1.keyup(validatePass1);
        
    pass2.keyup(validatePass2);
        
    message.keyup(validateMessage);

        function 
    validateName(){
            
    //if it's NOT valid
            
    if(name.val().length 4){
                
    name.addClass("error");
                
    nameInfo.text("We want names with more than 3 letters!");
                
    nameInfo.addClass("error");
                return 
    false;
            }
            
    //if it's valid
            
    else{
                        $.
    ajax({
                        
                        
    url:"/cgi-bin/isaccount3.cgi?username=" encodeURIComponent(name.val()),
                        
    type"GET",
                        
                        
    async:false,
                        
    success:function(data){

                            
    name.removeClass("error");
                            
    nameInfo.removeClass("error");

                            if(
    data=="yes"){
                                
    nameInfo.text("name ok");
                                
    nameInfo.removeClass("error");
                            }
                            if(
    data=="no") {
                                
    nameInfo.text("Name In Use");
                            }
                            return 
    true;
                            }

                        
                    });

                return 
    true;
            }
        } 
    The user is required to enter a username with a minimum 4 characters, if it is valid than it will check the availability of the username.

    Here's the problem. When I enter username longer than 4 characters, e.g. "peggy", I may get 2 data: "username=pegg" and "username=peggy".

    Any idea to fix it?

  8. Users who have thanked jackvan for this post:

    Solushunz (02-08-2012)

  9. #23
    New Coder
    Join Date
    Jan 2012
    Posts
    24
    Thanks
    1
    Thanked 1 Time in 1 Post
    I've fixed the problem by changing keyup() to focus():

    PHP Code:
        //On focus 
        
    name.focus(validateName); 
        
    name.focus(validateName); 
        
    pass1.focus(validatePass1); 
        
    pass2.focus(validatePass2); 
        
    message.focus(validateMessage); 
    I've learned a lot from you. My Form Validation is working wonderfully. Thanks again for your time.
    Last edited by jackvan; 01-30-2012 at 05:53 PM.


 
Page 2 of 2 FirstFirst 12

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •