I’m fairly new to js, having to learn alot while I go so apologies if this is an easy question.
I need to change the code below so that it will check to see if there is a value for the model variable, its a select dropdown in a form.
If there is no value then I don’t want the var model to be included in the url part.
I also need to check to see if the var pics is checked (its a checkbox) if its checked then i want to include it, if its not checked then again I need to miss it our from the url part.
Can anyone help me please? I’ve posted a few help threads on here now with no-one repling, if I’ve not given enough detail with this for anyone to be able to help me please tell me. I really need help with this, I’ve posted the full js function below.
Thanks in advance.
function ajaxFunction(){
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 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;
var keywords = document.getElementById('keywords').value;
var queryString = "?drop_1=" + drop_1 + "&model=" + model + "&mileage=" + mileage + "&colour=" + colour + "&min_price=" + min_price + "&max_price=" + max_price + "&min_engine_size=" + min_engine_size + "&max_engine_size=" + max_engine_size + "&pics=" + pics + "&keywords=" + keywords;
ajaxRequest.open("GET", "filtered-cars.php" + queryString, true);
ajaxRequest.send(null);
}