1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Trying to find the GET value

Discussion in 'jQuery' started by adamjblakey, Dec 1, 2010.

  1. #1
    Hi,

    I have the following function running:

    
    <script type='text/javascript'>
    $(function(){
    
    	$("form#search-form").submit(function(){
    		$("#search-text").animate({"width":"229px"});
    		$("#results").fadeOut();
                    var allVars = $.getUrlVars();
                    var byName = $.getUrlVar('service');
    
    		$.ajax({
    			type:"GET",
    			data: $(this).serialize(),
    			url: "search.php?sp=",
    			success: function(msg)
    				{
    				$("#results").html(msg);
    				$("#results").fadeIn();
    				$("#search-text").html("<a href='#' id='search-again'>Search Again</a>");
    				}
    		});
    	return false;
    	});
    	
    	$("#search-again").live("click", function()
    		{
    			$("#search-text").html("Search");
    			//$("#search-text").animate({"width":"58px"});
    			$("#search-text").width("58px");
    			$("#search-form").fadeIn();
    		});
    });
    </script>
    
    Code (markup):
    And on this line url: "search.php?sp=",

    I want to put a get value after the = symbol.

    The url i have is: www.mysite.com/?service=test

    I want want to get the value of service.

    I found this website here: http://jquery-howto.blogspot.com/2009/09/get-url-parameters-values-with-jquery.html which you can get get values with jquery but am unsure on how to implement this into what i already have.

    Thanks in advance,
    Adam
     
    adamjblakey, Dec 1, 2010 IP
  2. cshwebdev

    cshwebdev Active Member

    Messages:
    226
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    80
    #2
    The easiest way is to simply call PHP to do the work.

    Here:
    
    <script type='text/javascript'>
    $(function(){
    
    	$("form#search-form").submit(function(){
    		$("#search-text").animate({"width":"229px"});
    		$("#results").fadeOut();
                    var allVars = $.getUrlVars();
                    var byName = $.getUrlVar('service');
    
    		$.ajax({
    			type:"GET",
    			data: $(this).serialize(),
    			url: "search.php?sp=<?php echo $_GET['service']; ?>",
    			success: function(msg)
    				{
    				$("#results").html(msg);
    				$("#results").fadeIn();
    				$("#search-text").html("<a href='#' id='search-again'>Search Again</a>");
    				}
    		});
    	return false;
    	});
    	
    	$("#search-again").live("click", function()
    		{
    			$("#search-text").html("Search");
    			//$("#search-text").animate({"width":"58px"});
    			$("#search-text").width("58px");
    			$("#search-form").fadeIn();
    		});
    });
    </script>
    
    Code (markup):
    Just remember to save it as .php if you are currently using .html.
     
    cshwebdev, Dec 1, 2010 IP
  3. adamjblakey

    adamjblakey Active Member

    Messages:
    1,121
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    80
    #3
    Thanks a million :)
     
    adamjblakey, Dec 1, 2010 IP