+ Start a Discussion
mallikammallikam 

Issues with command button

I have custom objects save command button on my page. Whenever I hit the enter key, the save command button is getting exectued and I want to avoid this. Instead, whenever a enter key is entered, I want the cursor to go the next corresponding field or in other words, I want to have control over enter key..how can I achieve it?
Message Edited by mallikam on 07-09-2009 09:38 AM
Best Answer chosen by Admin (Salesforce Developers) 
AlsoDougAlsoDoug

Pretty sure the normal default standard (IE you did plan HTML) would be enter on a field (except text area) is a submit.

 

That having been said you have

 

http://www.bloggingdeveloper.com/post/Disable-Form-Submit-on-Enter-Key-Press.aspx

 

Not sure how well this would work since it appears to go on the body which I am not sure we have access to here and you don't want to use the onkeypress.

 

 

 

 

All Answers

AlsoDougAlsoDoug

That would be breaking standard website functionality.

 

It would be like writing code to make check boxes work like radio buttons.

 

That having been said you would need to override the onkeypress event in javascript and change the enter to a tab.

 

http://www.w3schools.com/jsref/jsref_onkeypress.asp

 

I think you would have problems with text areas so you would probably need logic to deal with that.

 

 

mallikammallikam
Not exactly!! I have seen webpages where the enter key goes to the next field. Forget about that..have you seen a webpage where if you hit an enter key, it just submits the page!! Thats waht is happening on my VF page and its not a very good functionality any page can have because the user might just hit enter key accidentally. I know about onkey press event. If I use it, I am running the JS event everytime the user types something, I dont want that to happen..but again, I dont want the enter key trigger the page submission everytime I use it!!
Message Edited by mallikam on 07-09-2009 10:25 AM
AlsoDougAlsoDoug

Pretty sure the normal default standard (IE you did plan HTML) would be enter on a field (except text area) is a submit.

 

That having been said you have

 

http://www.bloggingdeveloper.com/post/Disable-Form-Submit-on-Enter-Key-Press.aspx

 

Not sure how well this would work since it appears to go on the body which I am not sure we have access to here and you don't want to use the onkeypress.

 

 

 

 

This was selected as the best answer
mallikammallikam
Thanks, Doug! I guess I just have to settle with this solution eventhough I dont prefer to use onkeypress event..I dont see any other option!! I dont think its IE's default though...I think its how the VF page event handler is working!!
AlsoDougAlsoDoug
Life is about compromises :)

 

mallikammallikam

Make it "Software is about compromises"..life has got so many options!! :)