Forum Moderators: coopster & phranque

Message Too Old, No Replies

IE issues with <button> and <input type=image>

IE problems on forms with multiple buttons

         

yjtanaka

12:30 am on Jul 8, 2008 (gmt 0)

10+ Year Member



I've come across 3 issues with IE when using buttons, especially with a form containing multiple instances of buttons. This forum provided me the most insight (though not complete), so I wanted to share my findings. If you have come across better solutions, please chime in.

Please note that I have to stay away from JavaScript, because our users like to be able to perform all of the actions from Treos, Blackberrys, etc. Therefore, I need a purely server-side solution.

As far as I can tell, Firefox, Opera, Safari comply with the HTML specification, and IE does not seem to comply with the following 3 issues.

1. Value of <button> not handled properly in IE

<button name="abc" value="xyz"> Go to Next Step </button>
All browsers, except IE, will pass name-value pair of "abc" and "xyz", and display "Go to Next Step" on the button. However, in IE, the "value" attribute is ignored and the actual value passed is "Go to Next Step". This is quite annoying, but can be worked around.

2. Inside a form with multiple buttons, clicking on one button will submit values for all buttons in IE

This problem exceeds being annoying, and will necessitate changing your code. If one has a form with multiple button actions, the only way to determine which button was pressed is to use <input type="submit"> or <input type="image">. <input type="submit"> is annoying, because the "value" attribute is used both as the value and the display string. But this is nothing compared to ...

3. <input type="image" name="abc" value="xyz"> only submits x and y coordinates in IE

This is truly awful. On HTML-compliant browsers, the following parameters will be passed, with corresponding values:

abc xyz
abc.x 5 (example ... 5 pixels from left)
abc.y 8 (example ... 8 pixels from top)

However, with IE only the .x and .y values are passed:

abc.x 5 (example ... 5 pixels from left)
abc.y 8 (example ... 8 pixels from top)

I have a rather complicated form with many input fields and a section to upload a file, download files in the repository, and show revisions of files in the repository. In order to preserve all the information in the input fields, even if the user uploaded/downloaded/or checked revisions before submitting the form, all of these elements are in one form. What's more the "download" and "show revisions" functions enumerate over arbitrary number of files. I was using the "value" attribute to pass the filename for these functions, but it won't work with IE.

The work-around was to prefix the "name" attribute with the function (either "download" or "showrev"), and to suffix it with the filename (i.e. desired "value"). For example:
<input type="image" name="download_Q2results.xls">
<input type="image" name="showrev_Q2results.xls">
<input type="image" name="download_Q3results.xls">
<input type="image" name="showrev_Q3results.xls">

So, basically making the "name" attribute a composite of the "name" "value" pair.

Then, since I prefer not to add conditional code based on client browser type, I would look for the longest parameter that starts with "download_" or "showrev_". Then, I would substitute out trailing ".[xy]". I do this because it is possible to have the original filename end in .x.

Anyway, the following is the code snippets to make a complex multi-input, multi-button form work in both Firefox and IE.

From script that creates the input form:
print "<input type=\"image\" name=\"download_$file\" value=\"$file\" src=\"$webroot/downArrow.png\"> $file </input>\n";

From script that determines which button was pressed:
@params = param;
if ( @downloadFile = grep ( /^download_/, @params ) ) {
foreach $x ( @downloadFile ) {
if ( $downloadFile ) {
$downloadFile = $x if ( length ($x) > length ($downloadFile) );
} else {
$downloadFile = $x;
}
}
$downloadFile =~ s/^download_//;
$downloadFile =~ s/\.[xy]$//;
}

if ( $downloadFile ) {
... download file ...
}

Anyway, I don't use IE, so I didn't even suspect anything will be broken in IE for such a server-side-heavy application. Then, after finding out the IE issues, trying to figure out what exactly was not working was very tedious. In the end, with a little work, one can still do pretty much anything with pure-server-side computing. Perl makes it easy.

Maybe there are more elegant ways or completely different solutions to the above, and I would really appreciate hearing about them. Please be reminded that original problem statement starts with a very complex form where one section has many input elements, and another section has file upload/download/show rev actions. In the middle of editing the input fields, user might decide to upload/download/showrev files, and when they return, they don't want their work to have disappeared. There is a "submit" button at the bottom to submit the edited input fields. Use of JavaScript or ActiveX is not allowed.

yjtanaka

12:34 am on Jul 8, 2008 (gmt 0)

10+ Year Member



I'm sorry. I'm a newbie to this forum, and it looks like I should have used "[" and "]" so the code would appear in easy-to-read format. Next time.

perl_diver

2:07 am on Jul 8, 2008 (gmt 0)

10+ Year Member



hmmm...... The forum is for asking questions. Maybe there is a tutorials or articles section where this is more appropriate.

yjtanaka

4:17 am on Jul 8, 2008 (gmt 0)

10+ Year Member



Well, my question was ... is there any other way?

perl_diver

4:28 pm on Jul 8, 2008 (gmt 0)

10+ Year Member



Oh..... don't use button tags or "intput type=images". Use "input type=submit" widgets and put images on them using CSS.

yjtanaka

5:35 am on Jul 9, 2008 (gmt 0)

10+ Year Member



Thanks for the suggestion. Unfortunately, I need to stay away from client-dependency (JavaScript, ActiveX, CSS, etc) as users need to access from thin clients like Treo, Blackberry, Sidekick.

It's just a sad testament that simply because Microsoft never understood server-side-computing at the core, the rest of us have to suffer with a sundry of work-around's and kludges.

Anyway, I'll try re-posting the code snippet in (hopefully) an easier-on-the-eye format for anyone who's looking for pure-server-side solutions. Hopefully, the

 will maintain the indenting. Essentially, "download" is the *name* of the "function", and the suffix is the arg (value).

[code]
@params = param;
if ( @downloadFile = grep ( /^download_/, @params ) ) {
foreach $x ( @downloadFile ) {
if ( $downloadFile ) {
$downloadFile = $x if ( length ($x) > length ($downloadFile) );
} else {
$downloadFile = $x;
}
}
$downloadFile =~ s/^download_//;
$downloadFile =~ s/\.[xy]$//;
}


if ( $downloadFile ) {
... download file ...
}

perl_diver

6:35 am on Jul 9, 2008 (gmt 0)

10+ Year Member



this forum has very poor code formatting. I usually just use the quote tags for posting code. Are you using the CGI module to parse the form data? It might already take this odd situation into account.

andrew

10:39 am on Sep 19, 2008 (gmt 0)

10+ Year Member



It's a bit late now, but in reply to your original three issues, I've also encountered them.

Issue 1) Microsoft's own website confirms the behaviour you're seeing: (http://msdn.microsoft.com/en-us/library/ms535211(VS.85).aspx). IE8 (beta), using its standards mode, will submit the value attribute of a button element, but in all other versions, the inner text element is submitted, in direct contradiction to the HTML 4.01 standard (http://www.w3.org/TR/html401/interact/forms.html).

Issue 2) I haven't found anything on Microsoft's website about this, but I've encountered the issue in my own testing as well. Again, this behaviour is contradictory to the HTML 4.01 standard.

Issue 3) On this one as well, IE is not compliant with the HTML 4.01 standard, as their website also confirms (http://msdn.microsoft.com/en-us/library/ms535836(VS.85).aspx). This time it seems they have no intention of fixing it.

So sorry, no help here, just confirmation that you've got to work around it. Probably the best way is to use graphical submit buttons (<input type="image">), with each button having a different name. As long as they're input elements and not button elements, only the successful one will be sent back to the server, so on the server side look for the presence of a query string parameter of name.x or name.y, which will tell you which submit button was used.

Of course, you've probably figured all this out by now :)

[edited by: phranque at 12:52 am (utc) on Sep. 20, 2008]
[edit reason] disabled smileys ;) [/edit]