By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,978 Members | 1,467 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,978 IT Pros & Developers. It's quick & easy.

ENTER key to submit forms

P: n/a
Hello,

I want to know what I have to do to make the enter key to submit forms. I
read in another newsgroup that inserting an html hidden text box made the
trick, and it actually does, but in my page I have more than one web control
that have their independient "forms" (in the .NET environment, it makes it
to be just one). And I need that, if the user is, say, writing the keywords
to perform a search, the enter key submits this form, but if he is writing
his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC
Nov 18 '05 #1
Share this Question
Share on Google+
11 Replies


P: n/a
Sandra,

I've created a javascript component with some commonly used javascripts in
it. One of them does exactly what you are looking for.

The component is free, comes with a help file, and the entire projects
source code is available on my web site: www.aboutfortunate.com. Just click
on the code library link and then click on the "Javascript" button in the
menu on the left.

Even if you don't want to use the entire component the code you need to
create your own is in the project.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I
read in another newsgroup that inserting an html hidden text box made the
trick, and it actually does, but in my page I have more than one web control that have their independient "forms" (in the .NET environment, it makes it
to be just one). And I need that, if the user is, say, writing the keywords to perform a search, the enter key submits this form, but if he is writing
his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC

Nov 18 '05 #2

P: n/a
Hi,

Thank you very much for the code, but I still have one problem, and it is
that .NET is the one that builds the form, and it always gives it the name
of the page, for example if the page is Default.aspx, the name of the form
will be FormDefault. These "forms" I have are in web controls, and they are
included in many different pages. So I can't use the name of the form like
that.... Is there anything like document.forms(0).thebutton?

Thanks again and bye

SC
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eV*************@tk2msftngp13.phx.gbl...
Sandra,

I've created a javascript component with some commonly used javascripts in
it. One of them does exactly what you are looking for.

The component is free, comes with a help file, and the entire projects
source code is available on my web site: www.aboutfortunate.com. Just click on the code library link and then click on the "Javascript" button in the
menu on the left.

Even if you don't want to use the entire component the code you need to
create your own is in the project.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web

control
that have their independient "forms" (in the .NET environment, it makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC


Nov 18 '05 #3

P: n/a
Sorry, ignore the previous message, I was just being stupid.

SC
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eV*************@tk2msftngp13.phx.gbl...
Sandra,

I've created a javascript component with some commonly used javascripts in
it. One of them does exactly what you are looking for.

The component is free, comes with a help file, and the entire projects
source code is available on my web site: www.aboutfortunate.com. Just click on the code library link and then click on the "Javascript" button in the
menu on the left.

Even if you don't want to use the entire component the code you need to
create your own is in the project.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web

control
that have their independient "forms" (in the .NET environment, it makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC


Nov 18 '05 #4

P: n/a
I'm sorry, could you please tell me how to attach this eventhandler to my
textboxes? I am working with <asp:textbox>. does it work with them?
Sorry :'(

SC
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I
read in another newsgroup that inserting an html hidden text box made the
trick, and it actually does, but in my page I have more than one web control that have their independient "forms" (in the .NET environment, it makes it
to be just one). And I need that, if the user is, say, writing the keywords to perform a search, the enter key submits this form, but if he is writing
his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC

Nov 18 '05 #5

P: n/a
Sandra,

No problem! :-)

It's pretty easy. Once you've dragged the component onto the page switch to
the code behind page.

If you didn't change the default name of the component when it was placed on
the page you would refer to it as: Javascript1

And you can attach it to as many text boxes as you want like this:

'---Page is the page object literally type "Page" there.
'---Textbox1 is the id of your text box.
'---Button1 is the id of the button you want to fire when the enter key is
' pressed while in this text box.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Javascript1.TextBoxEnterEventHandler(Page, TextBox1, Button1)
Javascript1.TextBoxEnterEventHandler(Page, TextBox2, Button2)
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
I'm sorry, could you please tell me how to attach this eventhandler to my
textboxes? I am working with <asp:textbox>. does it work with them?
Sorry :'(

SC
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web

control
that have their independient "forms" (in the .NET environment, it makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC


Nov 18 '05 #6

P: n/a
Being stupid again. It worked, thanks a lot :'(
SC
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I
read in another newsgroup that inserting an html hidden text box made the
trick, and it actually does, but in my page I have more than one web control that have their independient "forms" (in the .NET environment, it makes it
to be just one). And I need that, if the user is, say, writing the keywords to perform a search, the enter key submits this form, but if he is writing
his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC

Nov 18 '05 #7

P: n/a
Does it work if the user has the autocomplete enabled? In the page I added
the eventhandler, if I have autocomplete enabled, and I select an item from
the things with which I had filled that textbox before and I hit enter (just
as I always do), then it just does nothing, the form goes cleared and the
buttons don't work anymore.
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:O%****************@TK2MSFTNGP12.phx.gbl...
Sandra,

No problem! :-)

It's pretty easy. Once you've dragged the component onto the page switch to the code behind page.

If you didn't change the default name of the component when it was placed on the page you would refer to it as: Javascript1

And you can attach it to as many text boxes as you want like this:

'---Page is the page object literally type "Page" there.
'---Textbox1 is the id of your text box.
'---Button1 is the id of the button you want to fire when the enter key is
' pressed while in this text box.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Javascript1.TextBoxEnterEventHandler(Page, TextBox1, Button1)
Javascript1.TextBoxEnterEventHandler(Page, TextBox2, Button2)
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
I'm sorry, could you please tell me how to attach this eventhandler to my
textboxes? I am working with <asp:textbox>. does it work with them?
Sorry :'(

SC
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit
forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web control
that have their independient "forms" (in the .NET environment, it
makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC



Nov 18 '05 #8

P: n/a
Sandra,

It only works if the textbox has focus. That's the way javascript works. If
you don't click in the text box or move the cursor when you use autocomplete
to select something the text box doesn't have focus the autocomplete drop
down does. I have no idea how to attach a javascript to that.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
Does it work if the user has the autocomplete enabled? In the page I added
the eventhandler, if I have autocomplete enabled, and I select an item from the things with which I had filled that textbox before and I hit enter (just as I always do), then it just does nothing, the form goes cleared and the
buttons don't work anymore.
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:O%****************@TK2MSFTNGP12.phx.gbl...
Sandra,

No problem! :-)

It's pretty easy. Once you've dragged the component onto the page switch to
the code behind page.

If you didn't change the default name of the component when it was placed on
the page you would refer to it as: Javascript1

And you can attach it to as many text boxes as you want like this:

'---Page is the page object literally type "Page" there.
'---Textbox1 is the id of your text box.
'---Button1 is the id of the button you want to fire when the enter key is ' pressed while in this text box.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Javascript1.TextBoxEnterEventHandler(Page, TextBox1, Button1)
Javascript1.TextBoxEnterEventHandler(Page, TextBox2, Button2)
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
I'm sorry, could you please tell me how to attach this eventhandler to my textboxes? I am working with <asp:textbox>. does it work with them?
Sorry :'(

SC
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
> Hello,
>
> I want to know what I have to do to make the enter key to submit

forms.
I
> read in another newsgroup that inserting an html hidden text box

made the
> trick, and it actually does, but in my page I have more than one web
control
> that have their independient "forms" (in the .NET environment, it

makes
it
> to be just one). And I need that, if the user is, say, writing the
keywords
> to perform a search, the enter key submits this form, but if he is

writing
> his username and password to login, the enter key submits this other
> one........
>
> Does anyone know how to do this?
>
> Best Regards,
>
> SC
>
>



Nov 18 '05 #9

P: n/a
On a related note, I'm interested in AVOIDING having the form submitted when
a user hits the ENTER key (say just after selecting an Option button). Is
there a way to force the user to click the Submit button instead?

Thanks in advance,
Bill

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eV*************@tk2msftngp13.phx.gbl...
Sandra,

I've created a javascript component with some commonly used javascripts in
it. One of them does exactly what you are looking for.

The component is free, comes with a help file, and the entire projects
source code is available on my web site: www.aboutfortunate.com. Just click on the code library link and then click on the "Javascript" button in the
menu on the left.

Even if you don't want to use the entire component the code you need to
create your own is in the project.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web

control
that have their independient "forms" (in the .NET environment, it makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC


Nov 18 '05 #10

P: n/a
Sorry, I think there is a missunderstanding here. If the user has
autocomplete enabled in his browser, when the focus is in a textbox the
browser sometimes shows it the diferent things with which he has completed
that field, the user can, pressing the arrows select one of those and with
enter that item gets selected. All the time, the focus has been in the text
box. Now, if I have this handler for the keypressed event, that event is
raised when the user selects one word to fill the box. That's what is
happenning to me now
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:OM**************@TK2MSFTNGP10.phx.gbl...
Sandra,

It only works if the textbox has focus. That's the way javascript works. If you don't click in the text box or move the cursor when you use autocomplete to select something the text box doesn't have focus the autocomplete drop
down does. I have no idea how to attach a javascript to that.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uI**************@TK2MSFTNGP09.phx.gbl...
Does it work if the user has the autocomplete enabled? In the page I added
the eventhandler, if I have autocomplete enabled, and I select an item from
the things with which I had filled that textbox before and I hit enter

(just
as I always do), then it just does nothing, the form goes cleared and the buttons don't work anymore.
"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:O%****************@TK2MSFTNGP12.phx.gbl...
Sandra,

No problem! :-)

It's pretty easy. Once you've dragged the component onto the page switch
to
the code behind page.

If you didn't change the default name of the component when it was placed
on
the page you would refer to it as: Javascript1

And you can attach it to as many text boxes as you want like this:

'---Page is the page object literally type "Page" there.
'---Textbox1 is the id of your text box.
'---Button1 is the id of the button you want to fire when the enter

key is ' pressed while in this text box.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Javascript1.TextBoxEnterEventHandler(Page, TextBox1, Button1)
Javascript1.TextBoxEnterEventHandler(Page, TextBox2, Button2)
End Sub

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:Oi**************@TK2MSFTNGP10.phx.gbl...
> I'm sorry, could you please tell me how to attach this eventhandler
to my
> textboxes? I am working with <asp:textbox>. does it work with them?
> Sorry :'(
>
> SC
> "Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
> news:uX**************@TK2MSFTNGP12.phx.gbl...
> > Hello,
> >
> > I want to know what I have to do to make the enter key to submit

forms.
I
> > read in another newsgroup that inserting an html hidden text box

made the
> > trick, and it actually does, but in my page I have more than one

web > control
> > that have their independient "forms" (in the .NET environment, it

makes
it
> > to be just one). And I need that, if the user is, say, writing the
> keywords
> > to perform a search, the enter key submits this form, but if he is
writing
> > his username and password to login, the enter key submits this other > > one........
> >
> > Does anyone know how to do this?
> >
> > Best Regards,
> >
> > SC
> >
> >
>
>



Nov 18 '05 #11

P: n/a
Bill,

You could take the same script and instead of having it click the button
when the javascript senses that the enter key is pressed you could return
"false" which would make it as if the enter key was never pressed.

Something like this:
TextBox.Attributes.Add("onkeydown", "javascript:if((event.which &&
event.which == 13) || (event.keyCode && event.keyCode == 13)){return
false;}else return true;")

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Bill Cohagan" <bi**@teraXNOSPAMXquest.com> wrote in message
news:Ox**************@TK2MSFTNGP12.phx.gbl...
On a related note, I'm interested in AVOIDING having the form submitted when a user hits the ENTER key (say just after selecting an Option button). Is
there a way to force the user to click the Submit button instead?

Thanks in advance,
Bill

"S. Justin Gengo" <sj*****@aboutfortunate.com> wrote in message
news:eV*************@tk2msftngp13.phx.gbl...
Sandra,

I've created a javascript component with some commonly used javascripts in
it. One of them does exactly what you are looking for.

The component is free, comes with a help file, and the entire projects
source code is available on my web site: www.aboutfortunate.com. Just click
on the code library link and then click on the "Javascript" button in the menu on the left.

Even if you don't want to use the entire component the code you need to
create your own is in the project.

--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

Free code library at:
www.aboutfortunate.com

"Out of chaos comes order."
Nietzche
"Sandra Castellanos" <sa*****@4brainstorm.com> wrote in message
news:uX**************@TK2MSFTNGP12.phx.gbl...
Hello,

I want to know what I have to do to make the enter key to submit

forms. I read in another newsgroup that inserting an html hidden text box made the trick, and it actually does, but in my page I have more than one web control
that have their independient "forms" (in the .NET environment, it
makes it to be just one). And I need that, if the user is, say, writing the

keywords
to perform a search, the enter key submits this form, but if he is writing his username and password to login, the enter key submits this other
one........

Does anyone know how to do this?

Best Regards,

SC



Nov 18 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.