[jQuery] Re: submitting a form by pressing enter
A lot of browsers support usage without JS and CSS. Especially mobile devices or screenreaders have very bad JavaScript support, and screenreaders read the content of the page as it's shown without CSS. Even though we can argue for a long time whether or not it's a good idea to only support clients that have JS and CSS activated, it's all beside the point. My point was that if you have a form around your input fields, then it's easier to actually insert the submit button and through stylesheet, move it outside the viewable scope. You can't really use display: none; on the submit button. For some browsers it will remove the action of the button, so you are back to square one.. :) Oh, and lastly, why invent new things, when existing ones do exactly what is requested :) On Jun 26, 12:25 pm, tlob [EMAIL PROTECTED] wrote: A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave
[jQuery] Re: submitting a form by pressing enter
Well, you could do this in two ways, one is to actually make it into a form and the do something when the submit have been activated. The other way includes what you probably are looking for. You want to read the key that have been pressed. For this you need to register the keycode on the key down event on every input field inside the div. It should be something like this (although it have not been tested): $('#myDiv :input').keydown(function(e){ if (e.keyCode==13) { //do something when the enter key have been pressed - Enter key have the keycode of 13 } }); On Jun 26, 7:45 pm, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for your replies. I have a follow up question. Let's say I have a bunch of inputs, type=text within a div with id=myDiv. How do trigger an action if someone presses enter within one of those text fields? This would not be a form submission necessarily. - Dave On Jun 26, 5:25 am, tlob [EMAIL PROTECTED] wrote: A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave- Hide quoted text - - Show quoted text -
[jQuery] Re: submitting a form by pressing enter
Hy Steen I totally agree with you. And I did not know the CSS display:none will break the submit. Good to know! THX. cheers tl On Jun 27, 11:35 am, Steen Nielsen [EMAIL PROTECTED] wrote: A lot of browsers support usage without JS and CSS. Especially mobile devices or screenreaders have very bad JavaScript support, and screenreaders read the content of the page as it's shown without CSS. Even though we can argue for a long time whether or not it's a good idea to only support clients that have JS and CSS activated, it's all beside the point. My point was that if you have a form around your input fields, then it's easier to actually insert the submit button and through stylesheet, move it outside the viewable scope. You can't really use display: none; on the submit button. For some browsers it will remove the action of the button, so you are back to square one.. :) Oh, and lastly, why invent new things, when existing ones do exactly what is requested :) On Jun 26, 12:25 pm, tlob [EMAIL PROTECTED] wrote: A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave
[jQuery] Re: submitting a form by pressing enter
On 26 Giu, 06:20, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? hi. shouldn't this be a default?
[jQuery] Re: submitting a form by pressing enter
You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave
[jQuery] Re: submitting a form by pressing enter
A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave
[jQuery] Re: submitting a form by pressing enter
Thanks for your replies. I have a follow up question. Let's say I have a bunch of inputs, type=text within a div with id=myDiv. How do trigger an action if someone presses enter within one of those text fields? This would not be a form submission necessarily. - Dave On Jun 26, 5:25 am, tlob [EMAIL PROTECTED] wrote: A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave- Hide quoted text - - Show quoted text -
[jQuery] Re: submitting a form by pressing enter
It's been my experience that listening for keycodes in js can be a bit hairy. If you have a bunch of inputs, it's probably semantic to wrap them in a form (the div too if you like), then you could take advantage of the on built-in event listener but just prevent the actual form submission: $('#myForm').submit(function(e){ e.preventDefault(); doSomething(); }); On Thu, Jun 26, 2008 at 1:45 PM, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Thanks for your replies. I have a follow up question. Let's say I have a bunch of inputs, type=text within a div with id=myDiv. How do trigger an action if someone presses enter within one of those text fields? This would not be a form submission necessarily. - Dave On Jun 26, 5:25 am, tlob [EMAIL PROTECTED] wrote: A page is read without css? Hmmm I think that is really really really rare Even more rare than a browser without js turned on. Thats only really really rare ;-) Or what do you mean? instead of moving it away, why not css display:none;? Does this brake the submit? cheers tl On Jun 26, 10:22 am, Steen Nielsen [EMAIL PROTECTED] wrote: You need to insert a submit button in the form to get it working.. input type=submit if you don't want to show the button you can always hide it using CSS. I usually just positioning it -9000px to the left, that way it won't show up, but if the page is read without CSS, it will be shown correctly with a submit button On Jun 26, 6:20 am, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote: Hi, I have a form, with id=myForm, with a number of text fields (input with type=text). How do I cause a form submission by pressing enter in any of those form fields? Thanks, - Dave- Hide quoted text - - Show quoted text -
[jQuery] Re: submitting the form by pressing ENTER
You should be able to intercept that button press by using the submit() method of the form object. $('#myForm').submit(function(){ // this method should fire whether the button was clicked with the mouse // or the enter button was pressed return false; }); form id=myForm action=somepage.cfm input type=text name=textField / input type=submit value=submit me / /form -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 25, 2008 12:16 PM To: jQuery (English) Subject: [jQuery] submitting the form by pressing ENTER Hi, I have a form form id=previewForm name=previewForm with two buttons and a text field. What I would like is when I press enter on the text field, a JS function is invoked. What is the JQuery syntax to trigger this? Thanks, - Dave
[jQuery] Re: submitting the form by pressing ENTER
Hi, Unfortunately, that didn't work for me. Here was my code: $('#pageForm').submit(function() { var page = $('#page').val(); if (!isInteger(page)) { alert(The page number must be an integer.); return false; } if (!setCurrentPage(page)) { return false; } // if }); I did have success when I did form id=pageForm name=pageForm action=javascript:submitPageForm(); Damn, hate going back to the old ways. Oh well, - On Mar 25, 1:26 pm, Andy Matthews [EMAIL PROTECTED] wrote: You should be able to intercept that button press by using the submit() method of the form object. $('#myForm').submit(function(){ // this method should fire whether the button was clicked with the mouse // or the enter button was pressed return false; }); form id=myForm action=somepage.cfm input type=text name=textField / input type=submit value=submit me / /form -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 25, 2008 12:16 PM To: jQuery (English) Subject: [jQuery] submitting the form by pressing ENTER Hi, I have a form form id=previewForm name=previewForm with two buttons and a text field. What I would like is when I press enter on the text field, a JS function is invoked. What is the JQuery syntax to trigger this? Thanks, - Dave- Hide quoted text - - Show quoted text -
[jQuery] Re: submitting the form by pressing ENTER
In what way did it not work? It could be that your return false is inside an if statement. Mayne you're not making it into that if statement? -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 25, 2008 2:58 PM To: jQuery (English) Subject: [jQuery] Re: submitting the form by pressing ENTER Hi, Unfortunately, that didn't work for me. Here was my code: $('#pageForm').submit(function() { var page = $('#page').val(); if (!isInteger(page)) { alert(The page number must be an integer.); return false; } if (!setCurrentPage(page)) { return false; } // if }); I did have success when I did form id=pageForm name=pageForm action=javascript:submitPageForm(); Damn, hate going back to the old ways. Oh well, - On Mar 25, 1:26 pm, Andy Matthews [EMAIL PROTECTED] wrote: You should be able to intercept that button press by using the submit() method of the form object. $('#myForm').submit(function(){ // this method should fire whether the button was clicked with the mouse // or the enter button was pressed return false; }); form id=myForm action=somepage.cfm input type=text name=textField / input type=submit value=submit me / /form -Original Message- From: jquery-en@googlegroups.com [mailto:[EMAIL PROTECTED] On Behalf Of [EMAIL PROTECTED] Sent: Tuesday, March 25, 2008 12:16 PM To: jQuery (English) Subject: [jQuery] submitting the form by pressing ENTER Hi, I have a form form id=previewForm name=previewForm with two buttons and a text field. What I would like is when I press enter on the text field, a JS function is invoked. What is the JQuery syntax to trigger this? Thanks, - Dave- Hide quoted text - - Show quoted text -