input type image problem

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

input type image problem

Post by bouncer »

hi there,

Code: Select all

 <input type="image" src="../images/calendar.png" width="30" height="30" alt="Calendar" name="cmdCal" onClick='javascript&#058;window.open("calendar.php?formName=content_data&field=date_status","","top=50,left=400,width=175,height=140,menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no"); return false;'> 
i have this input tag in a webpage, but every time that i have the focus on a text field and press the Enter button it opens the calendar window instead of only open it on click, can anyone tell me what i'm doing wrong here ?

thanks in advance
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: input type image problem

Post by califdon »

bouncer wrote:hi there,

Code: Select all

 <input type="image" src="../images/calendar.png" width="30" height="30" alt="Calendar" name="cmdCal" onClick='javascript&#058;window.open("calendar.php?formName=content_data&field=date_status","","top=50,left=400,width=175,height=140,menubar=no,toolbar=no,scrollbars=no,resizable=no,status=no"); return false;'> 
i have this input tag in a webpage, but every time that i have the focus on a text field and press the Enter button it opens the calendar window instead of only open it on click, can anyone tell me what i'm doing wrong here ?

thanks in advance
That's the default behavior of any HTML element: if an element has the focus, pressing Enter is the same as clicking. I believe it is part of the accessibility features (for devices that don't use a pointing device). There may be a way to override it, but I don't know how. Perhaps someone else does.
bouncer
Forum Contributor
Posts: 162
Joined: Wed Feb 28, 2007 10:31 am

Re: input type image problem

Post by bouncer »

until i find a better solution i'll be using this js function ... :roll:

Code: Select all

 
function stopRKey(evt) {
  var evt = (evt) ? evt : ((event) ? event : null);
  var node = (evt.target) ? evt.target : ((evt.srcElement) ? evt.srcElement : null);
  if ((evt.keyCode == 13) && (node.type=="text")) { return false; }
}
 
document.onkeypress = stopRKey;
 
regards
Post Reply