Jump to content

[SOLVED] Driving me mad - onkeypress


marmite

Recommended Posts

Hi,

 

Can anyone tell me what's wrong with this code:

 

<input type="image" src="images/loginbutton.gif" onKeyPress="alert('hello');" id='loginbutton' name='loginbutton' width="80" height="17">

 

I've tried various " and ; variations. All I want is a pop-up when the user hits enter (it will tell them that they need to press the button)

 

Going mad ???

Link to comment
https://forums.phpfreaks.com/topic/49454-solved-driving-me-mad-onkeypress/
Share on other sites

I've given up and changed it to a submit.

 

If anyone's interested, it's to do with the fact that images don't have events in the same way as submits (ref nogray).

 

This article might help you (but it didn't help me): http://www.thescripts.com/forum/thread338775.html

Here is a quick demo on alerting using an image button (using the onsubmit event on the form)

<form onsubmit="alert('hello');">
<input type="text" />
<select><option>Select</option></select>
<textarea></textarea>
<input type="image" src="image_src" alt="submit" />
</form>

Notice the enter button only submit the button when it's clicked on the input type="text", it doesn't work from a select menu or a textarea.

 

You also can use a submit button if you want, just use CSS to add a background image, remove the borders and set the height and width. This will give you a graphical submit button.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.