Javascript Change Form Action Url

Handy stuff to know!

function goSearch() {

site_label = document.sform.site_id.options[document.sform.site_id.selectedIndex].value;
make_text = '';div_text = '';
search_text = document.sform.search.value;
if(typeof(document.sform.make_id) == 'undefined') {} else {
if(document.sform.make_id.options[document.sform.make_id.selectedIndex].value > 0) {
make_text = document.sform.make_id.options[document.sform.make_id.selectedIndex].text.replace(/ /g, '_');
div_text = '-';
}
}
url = '/search/' + search_text + div_text + make_text + '/' + site_label + '/';
document.sform.action = url;
document.sform.submit();
}

make_id = a form select box. in here we have the id of whatever this form is going to search for. the text between the option tags is what we want displayed in the URL along with anything in the search.value variable, seperated by the text_div value, which is a dash in this case.

So this is particularly handy for displaying search variables in the actual url. Generally you would then pick up those variables from Mod-Rewrite and use them as the same search vars as you're using in the Post (make_id), the idea is that you want to generate nice url's not just to be pretty but because you want those pretty vars to drive the navigation!

Sweet huh?

Additional information