O
OtisUsenet
Hello,
I am trying to call Javascript from FORM's onSubmit, and return false,
so the form is not actually submitted.
Normally I can just add 'return false;' to onSubmit to accomplish
this, like so:
<form name="XX" method="get" action="/Foo" onsubmit="onSearch();
return false;">
However, if my Javascript sets 'location.href', then my 'return
false;' is never executed:
<script type="text/javascript" language="JavaScript">
<!--
function onSearch() {
location.href = "/Bar?q=" +
encode(document.forms["XX"].elements["q"].value);
}
// -->
</script>
Is this a known behaviour? Are there any workarounds?
What is happening here is that instead of location.href getting set to
/Bar?q=..... and the browser going to that URL, my form's /Foo action
gets called, and that is what I am trying to avoid. Any ideas how I
can avoid /Foo getting called?
Thanks!
I am trying to call Javascript from FORM's onSubmit, and return false,
so the form is not actually submitted.
Normally I can just add 'return false;' to onSubmit to accomplish
this, like so:
<form name="XX" method="get" action="/Foo" onsubmit="onSearch();
return false;">
However, if my Javascript sets 'location.href', then my 'return
false;' is never executed:
<script type="text/javascript" language="JavaScript">
<!--
function onSearch() {
location.href = "/Bar?q=" +
encode(document.forms["XX"].elements["q"].value);
}
// -->
</script>
Is this a known behaviour? Are there any workarounds?
What is happening here is that instead of location.href getting set to
/Bar?q=..... and the browser going to that URL, my form's /Foo action
gets called, and that is what I am trying to avoid. Any ideas how I
can avoid /Foo getting called?
Thanks!