Preventing enter button to submit form

Hello ,

I am a newbie. When entering data in a form pressing enter submits the form. I want to avoid this. I found several answers by calling javascript in <body> tag of the page, which were similar to following link

I am unable to implement it in yii.

Any help is appreciated.

Thnks. :)

The simplest way to do this is to not use a submit button. Put your own non-submit button on your form and use an event handler to do the submit. I am not sure, however, if this works across all browsers. I bet IE will submit anyway.

Thnks for the idea, Works great with firefox but not with chrome. Is there any other method????

Any help is appreciated.

Did you try this ?

<form method="post" onsubmit="return false;" />

use this code in your head,it works fine for me in all browsers

<script type="text/javascript">

function stopRKey(evt) {

var evt = (evt) ? evt : ((event) ? event : null);

var node = ( ? : ((evt.srcElement) ? evt.srcElement : null);

if ((evt.keyCode == 13) && (node.type=="text")) {return false;}


document.onkeypress = stopRKey;