HTML form that redirects
I want to make a simple search box that redirects to an URL based on the input of the form, so if I search for "foo" the form would redirect the user to {{STATIC_URL}}/search/foo
I thought I accomplished this with the following code:
<script LANGUAGE="JavaScript">
function whatURL() {
window.location= window.location.protocol+'//'+window.location.host + "/search/" + document.form1.url.value;
}
</SCRIPT>
and
<FORM name=form1>
<input type=text id="urlval" name="url"onkeydown="if (event.keyCode == 13) document.getElementById('btnSearch').click()" >
<input type="submit" id="btnSearch" onClick="return whatURL();" value="Search">
</FORM>
but it only works when you hit enter, and not when you click on the button using the mouse (Safari 5.1). If I switch the input type from submit to button then the opposite is observed! Is there a better way to reme开发者_开发知识库dy this?
use the onSubmit handler for the form instead of the onClick handler.
精彩评论