[ACCEPTED]-HTML input box without a form-forms

Accepted answer
Score: 22

To get an input box without a form, I would 1 suggest just not using a form.

Score: 2

You will have to attach a onkeypress event 4 and check if enter was pressed (and rune 3 the code if it was). Tell us if you are 2 using plain JavaScript or some library if 1 you need examples.

Score: 1

It can be simply done with the help of a 2 form as follow... i think adding form would 1 provide great stability

<form onSubmit='alerttest(this); return false'>        
    <input type="text">         
</form>


<script language="javascript">
    function alerttest() {
        alert("Executing jolly.exe !!!!");
    }
</script>
Score: 0

To run a function when the user presses 9 enter when focused on the input field, the 8 easiest way would be to have the form tag 7 and run the function using the form's onSubmit event 6 (because pressing return when focused on 5 an input field submits the form).

If you 4 nevertheless don't want to include the form 3 tag, you can use the onKeyPress event to catch the 2 return key pressing and call the function 1 from there.

Score: 0

Don't use the form tag. You can easily use 4 JQuery to tie the code to the input control's 3 key press events.

If you are unfamiliar with 2 JQuery, just tie the code directly to the 1 input field key press event.

More Related questions