0

I have a htmlpage with three inputfields and a button. It looks like this:

i don't think it will help, but anyhow:

  <table>
        <tr>
            <td>Start:</td>
            <td><input ID="txtStart" type="text" /></td>
        </tr>
        <tr>
            <td>Eind:</td>
            <td><input ID="txtEind" type="text" /></td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td><input type="submit" onclick="javascript:alert('test');"/></td>
        </tr>
    </table>

    <table>
        <tr>
            <td>Station:</td>
            <td><input ID="txtStation" type="text" /></td>
        </tr>
    </table>

If i enter text in textbox 3 and i press enter, then button 1 fires an event(javascript:alert("this is a test");). How can i disable this? The button should only fire an event when i click it. It should not be related to textbox 3...

I think it has something to with postback or something? Or maybe a defaultbutton?

Any help welcome :)

  • Your question does not provide enough information. Add the HTML and JavaScript for the part of the page with your form elements and what events you're triggering. A good way to have a working example for us to respond to is to use http://jsfiddle.net – Tony Miller Mar 06 '12 at 15:39
  • i've added the code i'm using... – Ontwikkelaar Bij Debugged Mar 06 '12 at 15:45

4 Answers4

0

Your button may be marked as type="submit". If this doesn't solve can you post some HTML?

Adriano Repetti
  • 65,416
  • 20
  • 137
  • 208
0

Pressing ENTER in an input element within a <form> (in most browsers) triggers the submit action for that form.

The only way to avoid this is a little javascript intervention; Either add a check on the submit action of the form to test that all fields have been populated or catch the keypress event of the input element and discard any ENTER key presses.

See Also: How to prevent ENTER keypress to submit a web form? .

Community
  • 1
  • 1
Brad Christie
  • 100,477
  • 16
  • 156
  • 200
0

If you've got the textbox 3 and the button within the same <form> tag, the button will automatically be assigned to textbox 3 as well, thus Enter activates the submit button.

If you want to get rid of this, put it into another form (as you said textbox 3 isn't related to the button right?).

Harti
  • 1,480
  • 12
  • 16
0

if i use an asp:net button i can give that a property UseSubmitBehavior="false", that solved my problem! But anyhow, thank you!

Ron
  • 24,175
  • 8
  • 56
  • 97