Forum Moderators: open

Message Too Old, No Replies

I want to make a textfield submit upon enter key being pressed

         

indigojo

5:05 am on Mar 17, 2003 (gmt 0)

10+ Year Member



Any know an easy way to do this or some good articles. :)

DrDoc

8:58 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



By default the form will be submitted when you press enter. Which browser is causing the problem?

And, you're talking about regular input fields, not textareas, right?

indigojo

11:12 am on Mar 17, 2003 (gmt 0)

10+ Year Member



I'm talking about text areas and apparently theres a way to get them to act like regular text input fields ie upon enter key press they submit rather than jumping to a new line. I just can't find any info.

davemarks

11:19 am on Mar 17, 2003 (gmt 0)

10+ Year Member



That would sound rather silly as when someone presses enter to move to the next line (normal operation) they are going to submit the form

If you only want one line then use a normal text field

What are you trying to accomplish?

DrDoc

11:40 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It is possible to accomplish it, but I have to agree with davemarks - it's not wise to mess with something the user is used to, make something happen that is totally opposite to normal behavior.

However, if you have a good reason for wanting to accomplish something like that, then I'll let you know what you can do. First you should try solving it with normal input fields though...

Alternative Future

11:55 am on Mar 17, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi,

I think this is what you are looking for:

function entsub() {
if (window.event && window.event.keyCode == 13){
this.document.forms[1].submit();
}
}

<input type="text" name="searchText" size="25" value="" onkeypress="entsub()">

HTH,

-gs

indigojo

10:52 pm on Mar 17, 2003 (gmt 0)

10+ Year Member



Alernative future, thanks thats just what i was after.

Davemarks save your Jakob Nielsen rhetoric, I didnt ask whether i should do it but simply how to do it!

davemarks

10:57 pm on Mar 17, 2003 (gmt 0)

10+ Year Member



Sorry, I was just trying to be helpful.

I was just trying to make sure you had though about it, thats why I asked "What are you trying to accomplish?"

indigojo

11:04 pm on Mar 17, 2003 (gmt 0)

10+ Year Member



I am trying to please a client, they want "a bigger box and don't like how it does'nt work how it used to when it was smaller" get my drift.

DrDoc

12:39 am on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then, why don't you use CSS padding/width/height to change the size of the input field?

Please your client, but don't let them do something stupid. You're the expert, and you have to let them know that.

indigojo

12:56 am on Mar 18, 2003 (gmt 0)

10+ Year Member



The client uses nutscrape 4.7 so i'd steer clear of that kind of style control from past experience.

DrDoc

9:56 pm on Mar 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then the above code won't work anyway. NN4 doesn't understand window.event...

However, you need to tell your client that it's not good style, that it will make people confused. Thing is, though, width/padding/margin doesn't work in NN4 either.

Have you looked at the page in NN4? Are the input elements significantly smaller than in, say, IE?

If so, there are two alternative (and in my opinion "better") ways to solve what you're looking for.

1) If you're using the HTML4 standard you could use the <font> tag to make the input element bigger. Compare these two in NN4:

<font size="1"><input type="text" width="20"></font><br>
<font size="7"><input type="text" width="20"></font>

2) However, <font> tags are evil and should be avoided ;) There's a better solution. Add this to your style sheet:

input {
font-size: 32px;
/*/*/
font-size: 12px;
/* NN4 */
}

Try that in NN4. Then look at the page in IE (or any other browser) and you'll see the difference. The font sizes were just examples. But, at least you can make the input elements the same size by playing with font-size. The first line (32px) will be read by NN4. The second line (12px) is hidden from NN4, but will be read by other browsers.

Finally, tell your client (in a nice way) to upgrade. NN4 is based on technology from 1995 (yes, I know it says "Copyright 2001", but that's just when they made the last change to it. The technology is 1995.) I assume your client isn't using Win 3.1 still (or even Win95)? ;)

Ask why he/she likes NN4 so much, and introduce him/her to a Gecko browser instead ;) They are faster and better, and they have everything he/she is already used to, and more.