开发者

Why does adding a hidden text box to a form stop IE refreshing on enter

I was looking for a fix to stop IE refreshing the page instead of submitting my single line form, when a user hits enter instead of clicking go.

I found this solution, which works well, but I was wondering if anyone could explain why it works?

The solution I used is to add a hidden text inp开发者_运维问答ut within the form tags, like this

`<form name="SearchForm" id="SearchForm" method="get" action="">

/*This is the hidden text input*/
<input type="text" style="visibility:hidden;display:none;" name="ieSearchEnter">

</input>
<fieldset>
<span><input type="text" name="Search" id="Search"/></span>
<div class="field actions">
<input type="submit" name="Go" id="Go" class="submit" value="Go"/>
</div>

</fieldset>
</form>`

which i found here.

Thanks!


Are you really setting the ACTION value to an empty string, or did you just do that for your code sample?

I don't think IE is really "refreshing the page"-- I think it's automatically submitting your form.

Here's a simple test page: http://www.enhanceie.com/sandbox/simpleform.asp. When you hit enter, you'll see that the URL is updated to pass the user's value.

IIRC, there is code in IE's form-handling that says that if you have form containing a single test field, then hitting ENTER will submit that form. In your workaround, you've added an additional text field so that optimization is not applied.

I think maybe your server-side code is REQUIRING that the form submission contains "Go=Go" or it ignores the submitted value (Search=Whatevertheuserhadtyped) and simply re-displays the form. If you change the server-side script such that it does not require Go=Go, then your problem should go away.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜