One thing I learned was that IE and FF handle events like keypress, keydown, and keyup differently. IE especially makes it difficult when it auto-submits the form (and everything in MOSS content areas belongs to a form) on ENTER (char 13). The result can be a long ddddiiiiiinnnngggggg as the event fires off–far from ideal. For these reasons, I used keyup to fire the next javascript function and keypress was used to supress IE’s auto-submit.
One browser passes event.which while the other uses event.keycode. So there’s a special case for detecting which DOM element exists before you can check which key was pressed.
Another difference lies in the way FF and IE handle redirects. Windows.navigate simply doesn’t exist in FF’s DOM, so we use window.location.
Lastly, a button tag will auto-submit in FF so you need to use an input tag with type="button".
At any rate, the final working version is below. Don’t ask what doIdNumSearch() does, I didn’t write that.
<table border="0">
<tr>
<td class="ms-advsrchHeadingText" colspan="2">
<h3 class="ms-standardheader" style="font-size:
1em">
Search by number…</h3>
</td>
</tr>
<tr>
<td class="ms-advsrchText">
<label for="my_list_idnum">
<b>Number</b>:</label>
</td>
<td class="ms-advsrchText">
<input name="my_list_idnum" type="text" maxlength="200" id="my_list_idnum" onkeypress="return killEnter(event);" onkeyup="doSearch(event);">
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="button" value="Search" onclick="doIdNumSearch();" />
</td>
</tr>
</table>
<script type="text/javascript">
function
doIdNumSearch() {
var k =
document.getElementById(‘my_list_idnum’).value;
var loc = ‘results.aspx?k=’ + k + ‘contentclass:STS_ListItem_GenericList&s=my
list’;
window.location = loc;
}
function
doSearch(e) { //must fire on keyup because of IE
var
characterCode;
if(e
&& e.which){
e = e;
characterCode = e.which; //for most
browsers
}else{
e = event;
characterCode = e.keyCode; //for IE
}
if(characterCode
== 13){
doIdNumSearch();
}
}
function
killEnter(e){ //this stops IE from auto-submitting on ENTER
if(e.keyCode
== 13 || e.which == 13){
return false;
}
return true;
}
</script>