PDA

View Full Version : Disabling the Enter key



AllSystemGo
December 20th, 2007, 01:50 PM
Hi Guys,

A really simple question I guess, I would like to disable the Enter key on my website. I explain myself, I have a Global Directory Intranet that use AJAX. So when a user starts typing the desired name the search is already done on the LDAP server. But if the user, out of habit, press the enter key at the end of her search it, for reason unknow, reload the page, thus loosing here search.

I'm posting my code in case the problem reside in there.



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<title>Repertoire | Direction des Technologies de l'Information</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<style type="text/css" media="all">@import "../intranet/misc/drupal.css";</style>
<link href="css/style.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="scripts/pngfix.js"></script>
<script type="text/javascript" src="script/bottin.js"></script>
</head>
<body onload="setFocus()">
<div id="head">
<div id="logo"></div>
</div>

<div id="content" style="margin-left: 0px; margin-right: 0px">
<!-- begin content -->
<div class="tborder" style="margin-bottom: 2px;">
<div class="catbg" style="padding: 3px 6px 3px 6px; font-size: 15px; text-align: center;">
<img src="../intranet/themes/newsportal/images/globe.png" height="32" width="32" border="0" alt="Répertoire Globale"/> R&eacute;pertoire t&eacute;l&eacute;phonique de la Ville de Terrebonne
</div>
<div class="row2">
<div class="errorwrap" style="margin: 0px;padding-bottom: 0px;">
<h4>Attention!</h4>
<p>Voici les &eacute;tapes &agrave; suivre pour effectuer une recherche.</p>
<ul>
<li>Choisir une cat&eacute;gorie parmi les suivantes: Nom de famille, Pr&eacute;nom, Num&eacute;ro de poste</li>
<li>Inscrire dans le champs, &agrave; droite, le crit&egrave;re &agrave; rechercher</li>
<li>La recherche d&eacute;butera automatiquement</li>
<li>IMPORTANT: Vous ne devez pas appuyer sur la touche ENTR&Eacute;E pour d&eacute;marrer la recherche</li>
<li>Pour faire une recherche globale du r&eacute;pertoire vous devez mettre un * comme crit&egrave;re de recherche.</li>
</ul>
</div>
</div>
<div id="myMessage"></div>
<form id=formUserList name="formUserList">
</p>
<table width="100%" border=0 cellSpacing=0 cellPadding=1>
<tr>
<td nowrap width="10%">
<b>Effectuez une recherche par&nbsp;</b>
</td>
<td nowrap width="15%">
<select class="input" name="findBy" id=findBy onchange="removeText()">
<option value="last">Nom de Famille<br /></option>
<option value="first">Pr&eacute;nom<br /></option>
<option value="dn">Num&eacute;ro de poste<br /></option>
<option value="department">Direction<br /></option>
</select>
</td>
<td width="75%">
<input type="text" maxLength=40 size="40" name="pattern" id="pattern" value="" onkeyup="showUsers(findBy.value, this.value)">
</td>
</tr>
</table>
</form>
<div id="result_list"></div>
</div>
<!-- end content -->
</div>
<div class="tborder" id="footer">
Copyright 2007-2008 Direction des Technologies de l'information de la ville de Terrebonne. All rights reserved
</div>
</body>
</html>


My code isn't perfect, cause I'm only starting inthe HTML buisness, I'm still cleaning it up.

Thank you for your help.

Cheers

borrob
December 20th, 2007, 01:57 PM
this will work in ie and opera but not in firefox:

document.onkeypress = function()
{
if( window.event.keyCode == 13 )
{
return false;
}
}

if somebody knows a better way that will do it on all platforms i would like to know thx....

AllSystemGo
December 20th, 2007, 02:02 PM
Thank you for the quick reply borrob. I'll try you code on my site. One last question the document.onkeypress where do I put it??? On the <Body> tag??­­

borrob
December 20th, 2007, 05:14 PM
no it's a overwritten function ( document has it's own onkeypress ) that's why it returns false so the document onkeypress function is cancelled.
You should put it in an javascript section

<script language="JavaScript">
<!--

//-->
</script>