views:

129

answers:

2
<form id="form"   method="post" action="1.php">

<input name="checkbox"  type="checkbox"   checked="checked" value="ON" >

<input type="hidden" name="submitted2" value="TRUE" >
<input name="submitted1"  type="submit"   value="Apply"  >


<input type="submit" name="submitted2" value="OK" />
</form>

On selecting the checkbox and pressing the "Enter" hardkey, I want OK to be executed

A: 

You can use javascript to detect the enter and submit the form.

http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml

Paul
What Paul is implying is that pressing Enter on checkboxes doesn't trigger a form submit. That is (generally) only true of textboxes.
Ryan Kinal
@Ryan Kinal - That's probably not his issue. The issue here is that it's `submitted1` that fires on Enter, not `submitted2`.
Gert G
Ah, good point.
Ryan Kinal
A: 

Hello,

Please make few updation in your form. Updated One :

<input name="checkbox" type="checkbox" checked="checked" value="ON" onkeypress="return runScript(event)" id="checkbox">

//Add following code in Javascript

function runScript(e) {
    if (e.keyCode == 13) {
        var tb = document.getElementById("checkbox");
        eval(tb.value);
        return false;
    }
}
if(characterCode == 13)
{
    return false; // returning false will prevent the event from bubbling up.
}
else
{
    return true;
}

In order to run some "user defined" script from this text box when the enter key is pressed, and not have it submit the form, above is some sample code. Please note that this function doesn't do any error checking and most likely will only work in IE.

I hope this work for You !!!!

Rahul Patil