Hi,
In my application I can request a different URL based on a forms drop down and and a text value. I want to be able to submit via enter key but the code below doesn't work. The enter key ignores my location.href assigment and the page simply refreshes to its current location:
For example, if I select Collections from the drop down box and type c in the text box and then *click* submit, the URL requested from my server is:
If I select Collections and type c in the text box and click enter - I see the alert("Enter!") message and I see the alerts in the testResults function but the browser requests:
which is *really* wierd - those are the form field names.
Any help or guidance would be appreciated.
Thanks,
Phil
In my application I can request a different URL based on a forms drop down and and a text value. I want to be able to submit via enter key but the code below doesn't work. The enter key ignores my location.href assigment and the page simply refreshes to its current location:
Code:
<SCRIPT type="text/javascript">
function testResults (form) {
var TestVar = form.inputbox.value;
var searchType= form.searchtype.options[form.searchtype.selectedIndex].value;
// alert(searchType);
var searchURL = searchType + "?search=" + encodeURIComponent( TestVar)
// alert ("Search: " + searchType + "?search=" + TestVar + "\nURL: " + searchURL );
alert(searchURL);
location.href =searchURL;
}
</SCRIPT>
<SCRIPT TYPE="text/javascript">
<!--
function submitViaEnter(evt) {
evt = (evt) ? evt : event;
var target = (evt.target) ? evt.target : evt.srcElement;
var form = target.form;
var charCode = (evt.charCode) ? evt.charCode :
((evt.which) ? evt.which : evt.keyCode);
if (charCode == 13 || charCode == 3) {
alert("Enter!");
testResults(document.searchform)
// form.submit();
}
return true;
}
//-->
</SCRIPT>
<FORM NAME="searchform" ACTION="" METHOD="get">
<div id="shortcutSearch">
Search:x
<select NAME="searchtype">
<option value="donors.html">Donors</option>
<option value="specimenCollections.html">Collections</option>
<option value="specimenSearchResults.html">Results</option>
</select>
<INPUT TYPE="text" size="15" NAME="inputbox" VALUE="" onKeyPress="submitViaEnter(event)">
<INPUT TYPE="button" NAME="button" Value="Search" onClick="testResults(this.form)">
</div></FORM>
For example, if I select Collections from the drop down box and type c in the text box and then *click* submit, the URL requested from my server is:
If I select Collections and type c in the text box and click enter - I see the alert("Enter!") message and I see the alerts in the testResults function but the browser requests:
which is *really* wierd - those are the form field names.
Any help or guidance would be appreciated.
Thanks,
Phil