marmite Posted May 1, 2007 Share Posted May 1, 2007 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 ??? Quote Link to comment Share on other sites More sharing options...
fenway Posted May 1, 2007 Share Posted May 1, 2007 did you try onkeydown? Quote Link to comment Share on other sites More sharing options...
nogray Posted May 1, 2007 Share Posted May 1, 2007 The image type doesn't have an onKeyPress event because it doesn't take any input. Use onClick instead. If you want the alert to show when the user click the enter button, add it to the onsubmit event in the form. Quote Link to comment Share on other sites More sharing options...
marmite Posted May 2, 2007 Author Share Posted May 2, 2007 Thanks for the replies: onKeyDown doesn't work, either. OnClick does work but it isn't what I want - it pops up when people click the button: I want instead a pop-up when someone hits enter. Grateful for any ideas... Emma Quote Link to comment Share on other sites More sharing options...
marmite Posted May 2, 2007 Author Share Posted May 2, 2007 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 Quote Link to comment Share on other sites More sharing options...
nogray Posted May 2, 2007 Share Posted May 2, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.