Kaninepete
Kaninepete

Reputation: 1447

Changing what Enter button does on a simple form

My question is very similar to this one.

I really thought that <input type="text" name="StackOverflow1370021" value="Fix IE bug" style="{display:none}" /> would fix this.

For clarity, I want the Enter button to do what the "Change" button does. http://jsfiddle.net/RASgx/

Upvotes: 0

Views: 293

Answers (4)

Gabriel
Gabriel

Reputation: 18780

add return false; to your onSubmit handler to prevent the default.

Upvotes: 0

fabian-mcfly
fabian-mcfly

Reputation: 229

Change your tag to: <form name="text" onSubmit="document.getElementById('change').innerHTML=parseInt(document.getElementById('change').innerHTML)+parseInt((text.elements.field.value)); return false;"> That will prevent the form from being submitted.

Upvotes: 0

Cu7l4ss
Cu7l4ss

Reputation: 566

Although this is highly not recommended, you can add in the onsubmit at the end:

return false;

here is a fork of your code

Upvotes: 0

RichardTheKiwi
RichardTheKiwi

Reputation: 107716

You need to add a return false; to make it not submit

<form name="text" onSubmit="document.getElementById('change').innerHTML=parseInt(document.getElementById('change').innerHTML)+parseInt((text.elements.field.value));return false;">

Updated version (3) of your jsFiddle

Upvotes: 2

Related Questions