Saturday, August 28, 2004

HTML forms and ENTER

There are quite a number of occasions when I have to deal with forms that contains multiple submit buttons. A problem occurs when we need to specify a default submit button for user when user press the enter on any of the form elements. Usually for struts based framework, the developer will need to know which submit button is being clicked so the different functionality such as add, update or delete can be detected and performed. However, there is not clear guideline on which button will be submitted when a form submit without focusing on a submit button. An MSDN library article on submit button says that the first submit button will be used if none is on focus at the time of form submit is performed. Therefore certain workarounds such as creating a duplicate default submit button and placing it at the begining of the form and then hiding it using CSS are being suggested. Another suggestion which I found on this article; is to use a image submit button and set the size to 0. However, I am not sure this will be workable in my struts based project as I remember that the way struts framework handle image submit and normal submit is different. But then again, I could be wrong. If I ever encounter this scenario in this project, I think I will use <div style="display:none"><html:submit property="action">label</html:submit></div> just next to my html:form tag.

No comments:

Post a Comment