Forum Moderators: open

Message Too Old, No Replies

Enter Key no longer works to submit my Forms

I use a very obscure submit method...

         

joshdm

9:12 pm on Feb 9, 2005 (gmt 0)

10+ Year Member



I have a standard form on my page.
I may have multiple forms on the same page.

My submit buttons are printed as follows:

<div id="uniqueCssId">
<script type="text/javascript">
<!--
function submitThisForm(){ document.thisForm.submit(); }

document.write('<span><span><a href="javascript:submitThisForm()"><span>Button Text</span></a></span></span>');
// -->
</script><noscript><input type="submit" name="button_label" value="Button Text" alt="Button Text" title="Button Text" /></noscript></div>

The above is done so that an image can be placed on top of variable text ala the Sliding Doors.

When we hit the enter key on the form, it no longer submits the form. Any help would be... helpful.

bcolflesh

9:22 pm on Feb 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Did it work before? What changed - did you install the latest Windows updates from the other day? I noticed they increased cross-zone and client side security - could be an issue for you in IE.

joshdm

5:34 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



It's never worked ever since I implemented the above, which was months ago.

This is not a windows update problem.

The reason it's written as above is the following:

We have image-styled buttons for submission that may have variable width international text in them. Using the above, I can set images as backgrounds for the outer SPAN objects, use the Anchor and inner SPAN to position, and use the DIV to locate the item.

The NOSCRIPT is used because JavaScript is used to submit my form through the anchor. The Noscript replaces the entire item with an equivalent (ugly) form submit button.

I believe the problem stems from my use of the javascript call within the anchor tag, but I cannot solve.

joshdm

5:36 pm on Feb 10, 2005 (gmt 0)

10+ Year Member



Granted, the button/anchor tag does submit the form properly, and clicking on the button or anchor tag is the intent for submitting the form, but I've had enough complaints from the QA and Marketing guys who want to submit the form by hitting the ENTER key "just like on Amazon".

kaled

12:45 am on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's never worked ever since I implemented the above, which was months ago.

I looked at a similar problem some months ago. After some research and experimentation, I decided that it was impossible to achieve without using a standard submit button. I did, however, find an extemely complex script that claimed to solve the problem - but I didn't try it.

Incidentally, when using document.write to create tags, closing tags should be written thus :-

document.write('<\/span');

I have read that browsers may interpret </ as </script>.

Kaled.

gmiller

12:52 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Actually, it's "</" followed by any alphabetic character that ends a script or style element in standard HTML.

bruhaha

3:17 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



Here's a workaround I have used (which should work, unless a person has stylesheets turned off. . . in which case they should expect to see a messy page anyway!):

At the end of your javascript add in a simple version of the standard HTML submit button, but define the style to hide it from view. This gives you a submit button that the browser will recognize -- clicking on the visible image-button invokes the javascript; hitting "Enter" causes the form button to function in the usual way.

In other words, start with something like this:
<input type=\"submit\" value=\"Submit\" class=\"halfhid\">

Then define the class "halfhid" to hide the form button:

Originally I simply defined it as "width:0px; height:0px", so that that user sees nothing (1px/1px works just as well). That works just fine for IE. But in other browsers (e.g., Firefox) a small form button (about 16px by 4px) still appears, to the right of the image-button.

Solution? I have found two alternatives:

Alternative A:
1) add "display: block" to force the form button to show BELOW the image button
2) add "border: 1px solid #[color];" The color should match the background of the area below the button.

If for some reason this doesn't work for you (e.g. if you can't match the background below the image button, or display:block causes problems) you may use . . .

Alternative B:
1) (do NOT include "display:block") add "margin-left:-16px" to force the form button back into the area of the image-button (increase the number if you wish to push it further into the image)

2) use the "border" style above, but match the color of the image-button.

Drawback: If the mouseover image has a different background color (as they usually do) a small rectangle of the original image color will appear, but this will be only briefly, and if the mouseover image color is not radically different, the rectangle may be barely noticeable.

kaled

6:13 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm not sure I follow all the CSS stuff, but hiding a standard submit button is quite sneaky.

One other thought... take a look at [search.msn.com...] and see how they solved this problem.

Kaled.

bruhaha

8:58 pm on Feb 11, 2005 (gmt 0)

10+ Year Member



hiding a standard submit button is quite sneaky

I suppose it would be sneaky if you were fooling people and getting them to submit something without their knowledge. But using it to present the user with a nicer looking button AND give them exactly the same functionality as the form button alone --the functionality they EXPECT when they see your button-- what is "sneaky" about that?!

take a look at [search.msn.com...] and see how they solved this problem.

I assume you are referring to the Search button?Yes, one can also go that route.

In this case you would start with <input="submit" class="[mysubmit]". . . >. Define styles, using the desired image as a "background-image". (MSN does so by assigning the tag an ID#, but I usually use a class.)

By default the image will appear inside the button-box with the typical button border. To get rid of this simply add "border-width:0px" to the style(s).

To give you the idea, I have a button described thus in the stylesheet:

.blogin {
background-image: url(/images/login_button.gif);
width: 100px; height: 21px;
padding: 0px; border-width: 0px;
}

MSN doesn't have a mouseover (which I, perhaps incorrectly, assumed joshdm wanted). That can be accomplished by defining a new class with the mouseover image as the background-image. So, to replace the style above I have:

.bloginhi {
background-image: url(/images/login_button_hi.gif);
width: 100px; height: 21px;
padding: 0px; border-width: 0px;
}

To change the style onmouseover, simply add to the input tag:
onmouseover="this.className='[newclass]'"
onmouseout="this.className='[originalclass]'"

One other thing to be aware of with this method. The text you list as the VALUE of the submit button WILL appear on top of the button-image. You can, of course, give this text its own style. If the text is already part of your image, simply leave the value blank.

FWIW, the html for my image-button looks like this:
<input type='submit' value='' name='Login' class="blogin" onMouseOver="this.className='bloginhi'" onMouseOut="this.className='blogin'">

I did hesitate to list this approach because there is one place I tried to use it that will not function unless I fill in the VALUE. Not sure why that is so in just that one case. . . open to suggestions. . . .

kaled

11:53 pm on Feb 11, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I meant sneaky in a good (i.e. clever) way. I definitely didn't mean "underhand". I guess that's one of the problems with forums that span many countries. I'll try to choose my words more carefully.

Kaled.

kaled

10:41 am on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Having considered the idea of hiding a submit button, I think the best method might be a zero-height div. Assuming this is rendered correctly, it should be reliable. Hiding by other methods may cause enter-submit to fail on some platforms.

Kaled.

Bernard Marx

1:46 pm on Feb 12, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about using <input type="image">?

Granted, you couldn't use CSS for a rollover, but you could always use a little javascript to do this. No JS? - they don't get a rollover. No big deal.

This way there's no messing about with NOSCRIPT alternatives, and on the purist accessibility tip, no semantic misuse of elements.

bruhaha

5:31 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



the best method might be a zero-height div. Assuming this is rendered correctly, it should be reliable.

I agree. In fact, it is what I was proposing above (though I think that may have been lost in the details).

But please note that non-IE browsers will still show a small formbutton, no matter what you do. That is why it is necessary to stylize that formbutton to blend in with its background. The only reliable way I have found to do so is to give that button a solid 1px border the same color as the background on which it will be displayed.

bruhaha

5:43 pm on Feb 14, 2005 (gmt 0)

10+ Year Member



I meant sneaky in a good (i.e. clever) way. I definitely didn't mean "underhand".

Sorry for misunderstanding and if I seemed to take offense. (I was more surprised.) I don't think the problem in this case is so much the international nature of the forum as the fact that it is so difficult to discern "tone of voice" from the written word.

(An ancient problem, even for the best writers. In fact, according to some commentators, the apostle Paul once wrote to one of his churches something like: "I wish I were with you so you could hear my tone of voice.")