javascript - How to get CakePHP to send second submit button when pressing enter? -


i have find form 2 submit buttons: cancel , find. work both should when clicked. pressing enter key, 'cancel' submitted. not want change order of buttons in form. found solution prevent submission on 'enter' @ all. i'd have submit 'find' on enter. wrote javascript calls click action of find button when enter pressed. works nevertheless 'cancel' sent.

what's going wrong?

this form:

<?php echo $this->form->create(null,array('onsubmit' => 'return submitonenter(this);')); ?>   <table>     <tr>         <td><?php echo $this->form->input('find.num',array('autofocus'));?></td>     </tr>     <tr>         <td><?php echo $this->form->input('find.name');?></td>     </tr>     <tr>         <td><?php echo $this->form->input('find.address');?></td>     </tr>     <tr><td align="right">         <?php echo $this->form->submit('cancel',array('id'=>'cancel','name'=>'cancel','onmousedown' => 'itsclicked = true; return true;','onkeydown' => 'itsclicked = true; return true;')); ?>     </td></tr>     <tr><td align="right">         <?php echo $this->form->submit('find',array('id'=>'find','name'=>'find','onmousedown' => 'itsclicked = true; return true;','onkeydown' => 'itsclicked = true; return true;','onclick'=>"alert('the button clicked.');")); ?>     </td></tr>   </table> <?php echo $this->form->end(); ?> 

this javascript:

function submitonenter(form){     if(itsclicked){         return true;     }     document.getelementbyid('find').click();     return true; } 

'itsclicked' set false on page load.

please try this

this might not absolute answer question, lot.

please use below code cancel button

<?php echo $this->form->submit('cancel',array('type'=>'button','id'=>'cancel','name'=>'cancel','onmousedown' => 'itsclicked = true; return true;','onkeydown' => 'itsclicked = true; return true;','onclick'=>"cancelfind();")); ?> 

then use javascript function cancel operation:

function cancelfind(){   alert('do want do!'); } 

use below code find operation:

function submitonenter(form){   alert('do find operation here!.'); } 

thanks


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -