views:

526

answers:

2

Using IE 7, JDK 1.6 and Sun Web server 7.

Inside the jsp form, we have:

<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="send" value="Send"/>

i.e. a text box and a "Submit" button (called Send).

and the servlet has:

if (request.getParameter("send") != null && request.getParameter("send").trim().length() > 0) { ... }

Using Fiddler and IE, we can see that the following is sent when we populate the id text box and hit Enter:

id=123456

However, using Fiddler and IE, we can see that the following is sent when we populate the id text box and click the Send button:

userId=123456&send=Send

The end result is that hitting the Enter key effectively does nothing.

On other jsp pages, e.g. we have:

<input type="text" name="id" maxlength="20" />
<input ... type="submit" name="submitId" value="Submit"/>

and the servlet has:

if (request.getParameter("submitId") != null && request.getParameter("submitId").trim().length() > 0) { ... }

Using Fiddler and IE, we can see that the following is sent for both cases:

id=123456&submitId=Submit

So it seems to us that the behaviour is only exhibited on IE for forms where the "Submit" button is not called "Submit"?

Re-running the tests on Firefox 3.6 shows that the behaviour is correct and the same for both cases.

Any suggestions for getting IE to work correctly?

(Note: I have searched SO for a similar problem but the questions relating to this mainly all ASP related!).

A: 

Why are you checking for request.getParameter("submitId") in your JSP when in fact submitId is the name of your submit button?

In my experience I never had to check the value for the submit button. I only used that button to trigger the form submit and would usually only be interested in retrieving the values for the other form parameters.

If you want to differentiate the submit methods by the name of the submit button, you might want to try adding a "hidden" property using input type="hidden".

paul_sns
Uhm, the normal practice is that the presence of the name of the button in the request parameters is to be checked to distinguish the button pressed. You really don't want to use a hidden input element in combination with Javascript to distinguish it. The form would break if JS is disabled.
BalusC
Thanks BalusC. I wasn't really suggesting to use the hidden input with JS. I was thinking more in the lines of populating the value with server side scripts.But looking at your answer it seems this is a bug with IE so please just disregard my earlier suggestions. ;)
paul_sns
Wrt Javascript: I don't see other ways to distinguish the button pressed with only an `input type="hidden"` element :)
BalusC
+2  A: 

This is indeed another IE anomaly in case of forms with only one input field. The only solid workaround for this is to add a second input field(!). You can hide it using CSS. No, type="hidden" ain't going to work.

<input type="text" name="id" maxlength="20" />
<input type="text" style="display: none;" />
<input type="submit" name="send" value="Send"/>
BalusC
IE8 has it too.
axtavt
Drat, you're right. Mental note: don't overvalue IE8.
BalusC