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.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with Jquery

    Here is something that i've been working on the idea is that someone enters a valid url and then i have a php script that extracts info on the website and puts it into the input for. But for some reason when the i input a valid url i see the info i want which is the title of the page and then it dissapears quickly can someone help me out i am new to jquery.

    http://www.kuriyaki.com/simon/jquery/test.html

    you can try http://google.com

    you input into the first text box and then results will appear in second text box

    code


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <title>test</title>
    <script src="http://www.google.com/jsapi"></script>
    </head>
    <body>

    <form>


    <input type="text" id="website" size="100" />
    <br>
    <br>
    <input type="text" id="title" size="100" />
    <br>
    <br>
    <div id="container"></div>

    </form>

    <script type="text/javascript">

    google.load("jquery", "1.4.2");

    google.setOnLoadCallback(function() {

    var target = $( "#website" );
    var key = "";
    var websites = "";


    $('#website').keypress(function(e) {
    key = String.fromCharCode(e.charCode);
    websites = target.val() + key;
    $.get("test.php",{'func': websites},function(data){
    $("#title").val(data);
    $('#container').html(key);
    });

    });


    });


    </script>

    </body>
    </html>
    Last edited by jennova55; 05-18-2010 at 08:28 AM.

  • #2
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Is there some reason you've tied this to the keypress?

    Every time you type a character into the textbox, it's making a GET request to your PHP script. That's going to hammer your server a bit.

    I suspect that the problem you're seeing is that you've got all these GET requests queued up, and they won't necessarily return in the order you fired them off. So the one that returns a page title will finish, and populate your textbox, but then one of the previous twenty or so requests will finally finish and empty it again.

    Make sense?

  • #3
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yes i understand, is there a way for me to wait until the user is done with finishing input and then call my php script? some kind of simple function to check until user has finally input a valid url?

    thanks

  • #4
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Well, you could try matching the textbox value against a regular expression , but probably the simplest solution is to put a button that fires the lookup function next to the textbox, and let the user decide when they've finished entering their URL.


  •  

    Posting Permissions

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