html - JavaScript Change default button prob with firefox -


following problem:

i have list buttons, , after textbox button add new entry. in both, list buttons, , add button javascript routines confirm action.

now have problem, that, when user presses enter in textbox, first button if list invoked instead of add button. have added javascript in "onkeydown" event of button, use "return false;" avoid first button invoked after have checked return button pressed. works following line: onkeydown="if (event.which == 13) { return false; }" add javascript code before "return false;" (i need confirm message there , other javascript routines), firefox browser invoke first button , javascript code in onkeydown event... behavior not seem occur on internet explorer.

i have tried hours find solution, can't find 1 , can't find right hint on internet. glad if me on problem?

i have tried build code sample, can reproduce wrong behavior. in last input control have added onkeydown event. please tell me why firefox displays confirm message of first button, when press enter button in text input field?

<html> <head> </head> <body>     <form method="post" action="test.html" id="ctl00">     <div id="divtest">         <table>             <tr>                 <td>                     testline 1                 </td>                 <td>                     <input type="submit" onclick="if (confirm('sure?')) alert('the wrong postback'); else return false;" value="test1" />                 </td>             </tr>             <tr>                 <td>                     testline 2                 </td>                 <td>                     <input type="submit" onclick="if (confirm('sure?')) alert('the wrong postback'); else return false;" value="test2" />                 </td>             </tr>         </table>     </div>     <table>         <tr>             <td>                 enter name:             </td>             <td>                 <input type="text" size="30" onkeydown="if (event.which == 13) { alert('test'); return false; }" />             </td>             <td>                 <input type="submit" title="add it" onclick="alert('the correct postback')" />             </td>         </tr>     </table>     </form> </body> 

replace everywhere

type="submit" 

with

type="button" 

so hitting "enter" won't submit form.

but entire scheme strange : want submit form or not ? if so, why not having (as usual) 1 function checking fields ?


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -