SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Dec 2005
    Posts
    377
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question help please with using a variable from url in function

    Can someone please tell me how I would modify the following function to get it to check if a url variable is present and if so to add it into the string variable for the url.

    Code:
    function ajaxFunction(pagenum){
    	var ajaxRequest;  // The variable that makes Ajax possible!
    	
    	try{
    		// Opera 8.0+, Firefox, Safari
    		ajaxRequest = new XMLHttpRequest();
    	} catch (e){
    		// Internet Explorer Browsers
    		try{
    			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    		} catch (e) {
    			try{
    				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
    			} catch (e){
    				// Something went wrong
    				alert("Your browser broke!");
    				return false;
    			}
    		}
    	}
    	// Create a function that will receive data sent from the server
    	ajaxRequest.onreadystatechange = function(){
    		if(ajaxRequest.readyState == 4){
    			var ajaxDisplay = document.getElementById('ajaxDiv');
    			ajaxDisplay.innerHTML = ajaxRequest.responseText;
    		}
    	}
    	var drop_1 = document.getElementById('drop_1').value;
    	var model = document.getElementById('model').value;
    	var mileage = document.getElementById('mileage').value;
    	var colour = document.getElementById('colour').value;
    	var age = document.getElementById('age').value;
    	var min_price = document.getElementById('min_price').value;
    	var max_price = document.getElementById('max_price').value;
    	var min_engine_size = document.getElementById('min_engine_size').value;
    	var max_engine_size = document.getElementById('max_engine_size').value;
    	//var pics = document.getElementById('pics').value;
    	if (document.getElementById("pics").checked==true) {
    		var photos = "Yes";
    	}
    	else {
    		var photos = "No";
    	}
    	var keywords = document.getElementById('keywords').value;
    	var queryString = "?drop_1=" + drop_1 + "&model=" + model + "&mileage=" + mileage + "&colour=" + colour + "&age=" + age + "&min_price=" + min_price + "&max_price=" + max_price + "&min_engine_size=" + min_engine_size + "&max_engine_size=" + max_engine_size + "&photos=" + photos + "&keywords=" + keywords + "&page=" + pagenum;
    	ajaxRequest.open("GET", "filtered.php" + queryString, true);
    	ajaxRequest.send(null); 
    }
    If my url is index.php?make=Apolo then I need to get this added into the var queryString part of the function so that the ajax returns the correct values.


    any help would be greatly appreciated.

    Thanks in advance.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,527
    Mentioned
    84 Post(s)
    Tagged
    4 Thread(s)
    location.search will give you the querystring for the current page. It does have the question mark at the start though, so you may want to get only what comes after that, by using .substring(1)
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


Bookmarks

Posting Permissions

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