submitting a form by pressing "ENTER"

L

laredotornado

Hi,

I have a very simple form and I would like on Firefox and IE for the
form to submit upon the user pressing enter in the textfield. Right
now, I have

<script type="text/javascript">
function search() {
var search = document.getElementById('Search');
location = "search_response.php?Search=" + escape(search.value);
} // search
</script>
<form name="search" action="javascript:search();" method="get">
<table cellpadding="2" cellspacing="0" border="0" width="100%">
<tr><td class="departmentSidebarTitle" style="height:25px;
padding-left:3px; padding-right:3px;" nowrap>Search Store</td></tr>
<tr><td class="departmentSidebar" width="100%" align="left"><input
type="text" name="Search" id="Search" value=""></td></tr>
</table>
</form>

(this is all within a table cell), but it is not working. However,
there are no JS errors. Any ideas how I can tweak the above to make it
work?

Thanks, -
 
W

web.dev

Hi,

I have a very simple form and I would like on Firefox and IE for the
form to submit upon the user pressing enter in the textfield.

By default, all web forms will submit the form when a user presses
"Enter". There must be something else that's causing your form not to
behave correctly.
<form name="search" action="javascript:search();" method="get">

You are using the javascript pseudo protocol, which doesn't even belong
in the action attribute to begin with. Perhaps you meant the
following:

<script type="text/javascript">
function search() {
var search = document.getElementById('Search');
location = "search_response.php?Search=" + escape(search.value);
} // search
</script>

In your javascript, this is entirely unecessary. Your form uses the
GET method, therefore, your values will already be sent in the manner
that you're trying to achieve in your script.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top