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
    Regular Coder
    Join Date
    Dec 2009
    Posts
    173
    Thanks
    24
    Thanked 1 Time in 1 Post

    Jquery change function's not working.

    Code:
    <?php
    	if (isset($_GET['url'])){
    		$url = $_GET['url'];
    		$url = explode(" " , $url);
    		echo end($url);
    		exit;
    	}
    ?>
    <html>
    <head>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.js"></script>
    <script type="text/javascript">
    	$('input[type=text]').change(function (){
    		if ($(this).val() !== ''){
    			var url = $(this).val():
    			$.post('grab.php?url='+url+'', function (data){
    				window.open(data, 'Download', 'width=10,height=10');
    				$(this).html('');
    			});
    		}
    	});
    </script>
    </head>
    <body>
    <input type="text" style="width:100%;height:20px;"/>
    </body>
    </html>
    nothing happens when i paste content in the input. o.O

    Appreciate if someone could help me figure out this.

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,865
    Thanks
    6
    Thanked 1,029 Times in 1,002 Posts
    At first, put your document in standards mode (by using a proper doctype at the beginning, which means HTML 4/XHTML 1 strict or HTML 5). Then, the error console that comes with many browsers by default tells me:
    Unexpected token: ':' on line 7,
    which is this line:
    Code:
    var url = $(this).val():
    The colon should be a semicolon.

    And then, the actal reason why nothing is happening is because the input is non-existant when the script is invoked/cached. You need to execute it after the DOM has been constructed. I’m usually doing it like this:
    Code:
    if(typeof jQuery != 'undefined') {
    	$(function() {
    		// all the JS goes here
    	});
    }
    The outermost conditional check is to check if jQuery is actually loaded (if not, nothing happens). The following dollar funtion is the actual “if DOM is ready” check and all functions go in there.

  • Users who have thanked VIPStephan for this post:

    sorlaker (12-25-2011)

  • #3
    Regular Coder
    Join Date
    Dec 2009
    Posts
    173
    Thanks
    24
    Thanked 1 Time in 1 Post
    thank u so much!

  • #4
    Senior Coder DanInMa's Avatar
    Join Date
    Nov 2010
    Location
    Salem,Ma
    Posts
    1,577
    Thanks
    13
    Thanked 248 Times in 248 Posts
    nto sure what your end goal is, but jquery can also capture the paste event and trigger from that. http://www.mkyong.com/jquery/how-to-...r-with-jquery/


  •  

    Posting Permissions

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