ENTER key clearing form

E

Eric D. Braden

I feel like a fool for asking this; seems like I would have had more
luck with Google, but alas...

This is a little baby bit of code that a friend cooked up over a year
ago. My problem is simply that hitting enter doesn't really submit
the input. It just reloads with a cleared form. My desired effect is
for hitting the Enter key to have the same effect as clicking the
Submit button.

Here's the code:

<!-- saved from url=(0013)about:internet -->
<script language = "javascript">

function opensite()
{
location = "http://www.state.ar.us/dfa/personnel_mgmt/
classcodes/"+entry.num1.value+".txt";
}

</script>
<center>
<h2 align = "center">Enter the Class Code and click Submit</h2>



<form id = "entry">
<table>
<tr>
<td>
<input type = "text" id = "num1"></input>
</td>
</tr>
<tr>
<td align = "right">
<input type = "button" id = "submit" onclick = "opensite()" value =
"Submit"></input>
</td>
</tr>
</table>
</form>
</center>
<h3 align = "center"><font color = "Navy">You will find the MQs at the
bottom of the page.</font></h2>

I tried to make heads or tails of this post
:
http://groups.google.com/group/comp.lang.javascript/browse_thread
/thread/39d8b289a95afe79/10c205b5f6d17a0f?lnk=st&q=
javascript+enter+key#10c205b5f6d17a0f

but I couldn't get it working.

(and, yes, I know GoogleGroups is the devil, but I can't get a real
newsreader at work)
 
R

RobG

I feel like a fool for asking this; seems like I would have had more
luck with Google, but alas...

This is a little baby bit of code that a friend cooked up over a year
ago. My problem is simply that hitting enter doesn't really submit
the input. It just reloads with a cleared form. My desired effect is
for hitting the Enter key to have the same effect as clicking the
Submit button.

Irrelivant to your issue, which Randy has answered, but anyhow...
Here's the code:

<!-- saved from url=(0013)about:internet -->
<script language = "javascript">

The language attribute is deprecated, type is required:

<script type="text/javascript">

<URL: http://www.w3.org/TR/html4/interact/scripts.html#adef-language >

[...]

The center element is deprecated, use CSS styling instead.

<URL: http://www.w3.org/TR/html4/present/graphics.html#edef-CENTER >

[...]
<input type = "button" id = "submit" onclick = "opensite()" value =
"Submit"></input>

Closing tags for input elemens are forbidden.

<URL: http://www.w3.org/TR/html4/interact/forms.html#edef-INPUT >


There are other issues with your markup, use a validator. The W3C
HTML validator is pretty good:

<URL: http://validator.w3.org/ >
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top