Re: [Jason] Long Url from Search Form
So it has been months and this functionality was seems to have be forgotten. But now it has been found and we are working on it again!
The code works wonderfully, thank you again!
But we have 1 minor issue that we would like to change.
The coding as it is now, adds an "&" after each searched term. I understand the need for this , and why it is setup the way it is but, we would like to only display the "&" ONLY if it is necessary.
First, here is our js code:
<script type="text/javascript">
function submitSearch(form){
query="viewers/motorcycle_results.php?";
if(form.category.value!=""){query+="category="+form.category.value+"&";}
if(form.subcategory_match.value!=""){query+="subcategory="+form.subcategory_match.value+"&";}
if(form.cities_serviced_keyword.value!=""){query+="cities_serviced="+form.cities_serviced_keyword.value+"&";}
if(form.state_match.value!=""){query+="state="+form.state_match.value;}
window.location=query;
}
</script>
If someone utilizes all of the search form elements while searching the end of the url is great :".../motorcycle_results.php?category=Dual%20Sport%20Bikes&subcategory=Big%20Dog&cities_serviced=Townsend&state=CO"
But if someone searches using just the category drop down (2nd search form element) it leaves an unnecessary "&" at the end:
/motorcycle_results.php?category=Dual%20Sport%20Bikes&
I removed the "&" from the 4th element (state_match) since that is the last thing a user could choose and will never need one. But the various ways that people could possibly search, and the fact that none of the search options are required has confused us.
Is there a way to go about adding the "&" only if it is necessary, (ie. because another form element has been selected after it)?
Thanks!
Jason Glass