Connecting Tech Pros Worldwide Help | Site Map

Hitting Enter on a single text box

|-|erc
Guest
 
Posts: n/a
#1: Jul 20 '05
these 3 lines will put the following into the URL bar!
but with 2 input boxes it doesn't.

<form name=test>
<INPUT name='selqty2'>
</form>

file:///C:/WINDOWS/DESKTOP/tttt2.html?selqty2=55555


Is there a way to stop the URL bar changing and the page refreshing
when people press Enter on a single text input?

Herc

--
Yeah, I guess you're right.
[color=blue]
> Top posting can make things confusing.[/color]
[color=blue][color=green]
>> What's wrong with top posting?[/color][/color]


VK
Guest
 
Posts: n/a
#2: Jul 20 '05

re: Hitting Enter on a single text box


Yes, it's the default behavior. If there is only one single-line text
box in the form and you press Enter in it, it submits the form. Look at
the Google or any other search engine - you are using it everyday.

I'm not sure what do you expect in your case. If you just want to
disregard the Enter hits, try this:
<form onSubmit="return false;">
<input type="text" name="selqty2">
</form>




|-|erc <usemyonlineform@wwwadamskingdom.com> wrote in message
news:BMsib.110$4w2.5007@nnrp1.ozemail.com.au...[color=blue]
> these 3 lines will put the following into the URL bar!
> but with 2 input boxes it doesn't.
>
> <form name=test>
> <INPUT name='selqty2'>
> </form>
>
> file:///C:/WINDOWS/DESKTOP/tttt2.html?selqty2=55555
>
>
> Is there a way to stop the URL bar changing and the page refreshing
> when people press Enter on a single text input?
>
> Herc
>
> --
> Yeah, I guess you're right.
>[color=green]
> > Top posting can make things confusing.[/color]
>[color=green][color=darkred]
> >> What's wrong with top posting?[/color][/color]
>
>[/color]


Lasse Reichstein Nielsen
Guest
 
Posts: n/a
#3: Jul 20 '05

re: Hitting Enter on a single text box


"|-|erc" <usemyonlineform@wwwadamskingdom.com> writes:
[color=blue]
> these 3 lines will put the following into the URL bar!
> but with 2 input boxes it doesn't.[/color]

Actually, it does it with two input boxes too in my browser.
[color=blue]
> <form name=test>
> <INPUT name='selqty2'>
> </form>
>
> file:///C:/WINDOWS/DESKTOP/tttt2.html?selqty2=55555[/color]
[color=blue]
> Is there a way to stop the URL bar changing and the page refreshing
> when people press Enter on a single text input?[/color]

Pressing enter in a text input box will submit the form it is in.
Your form doesn't have an action attribute, which is required in HTML.
That is, your HTML is invalid. Fix that before going any further.

If you don't want to submit the form, you shouldn't have a form
element at all. (Generally, if you have an element and want to leave
out a required attribute, you are probably using it incorrectly.)

There is ofcourse the problem that Netscape 4 only accepts form
controls inside a form element. That means that if your page must
work in Netscape 4 (which is a browser so far from modern standards
that it ought to be dead and buried long ago), you must have the
form element.

A form control without a form is legal HTML. There is no way to submit
it, so you are probably using Javascript to access the control. That
means that your page depends on Javascript.

What you can do to make both Netscape and the HTML specification
happy, is to add an action attribute that directs the user to a page
that tells him why your page requires Javascript, and then use
Javascript to prevent the form from being submitted.

<form id="test" action="noJS.html" onsubmit="return false">
<input name="selqty2">
</form>

/L
--
Lasse Reichstein Nielsen - lrn@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
|-|erc
Guest
 
Posts: n/a
#4: Jul 20 '05

re: Hitting Enter on a single text box


"Lasse Reichstein Nielsen" <lrn@hotpop.com> wrote in[color=blue]
> "|-|erc" <usemyonlineform@wwwadamskingdom.com> writes:
>[color=green]
> > these 3 lines will put the following into the URL bar!
> > but with 2 input boxes it doesn't.[/color]
>
> Actually, it does it with two input boxes too in my browser.
>[color=green]
> > <form name=test>
> > <INPUT name='selqty2'>
> > </form>
> >
> > file:///C:/WINDOWS/DESKTOP/tttt2.html?selqty2=55555[/color]
>[color=green]
> > Is there a way to stop the URL bar changing and the page refreshing
> > when people press Enter on a single text input?[/color]
>
> Pressing enter in a text input box will submit the form it is in.
> Your form doesn't have an action attribute, which is required in HTML.
> That is, your HTML is invalid. Fix that before going any further.
>
> If you don't want to submit the form, you shouldn't have a form
> element at all. (Generally, if you have an element and want to leave
> out a required attribute, you are probably using it incorrectly.)
>
> There is ofcourse the problem that Netscape 4 only accepts form
> controls inside a form element. That means that if your page must
> work in Netscape 4 (which is a browser so far from modern standards
> that it ought to be dead and buried long ago), you must have the
> form element.
>
> A form control without a form is legal HTML. There is no way to submit
> it, so you are probably using Javascript to access the control. That
> means that your page depends on Javascript.
>
> What you can do to make both Netscape and the HTML specification
> happy, is to add an action attribute that directs the user to a page
> that tells him why your page requires Javascript, and then use
> Javascript to prevent the form from being submitted.
>
> <form id="test" action="noJS.html" onsubmit="return false">
> <input name="selqty2">
> </form>
>[/color]

nice detective work, return false works thanks to both of you.

Herc



Closed Thread


Similar JavaScript / Ajax / DHTML bytes