I have a search form that I'd like to use on my website to enter text in one box and use radio buttons to choose the search engine (either a site search or my library's catalog).
This code works in Firefox and Chrome but not IE and Safari:
<script type="text/javascript">
function dosearch() {
var sf=document.searchform;
var submitto = sf.sengines.value + escape(sf.searchterms.value);
window.location.href = submitto;
return false;
}
</script>
<form name="searchform" onSubmit="return dosearch();">
<input type="text" name="searchterms" size="20">
<input type="submit" name="SearchSubmit" value="Search">
<br />
<input type="radio" name="sengines" checked value="http://chelmsford.mvlc.org/search/keyword/">Catalog
<input type="radio" name="sengines" value="http://chelmsfordlibrary.org/?s=">Site
</form>
And I also have this code, which works in IE but not in Firefox:
<script>
function myFunction() {
var engine = document.forms[0];
var txt = "";
var term = escape(document.radiosearch.searchterms.value)
var i;
for (i = 0; i < engine.length; i++) {
if (engine[i].checked) {
txt = txt + engine[i].value;
}
}
window.location.href = txt + term;
}
</script>
<form name="radiosearch" onSubmit="return myFunction();">
<input type="text" name="searchterms" size="20">
<input type="submit" value="Search">
<br />
<input type="radio" name="engine" value="http://chelmsford.mvlc.org/search/keyword/" checked>Catalog</input>
<input type="radio" name="engine" value="http://chelmsfordlibrary.org/?s=">Site</input>
</form>
How can I merge or correct these so one bit of code will work in all browsers?