I can't believe that I didn't notice that.

On Mon, Oct 26, 2009 at 11:58 AM, Michel Belleville
<michel.bellevi...@gmail.com> wrote:
> Forms already submit when the enter is pressed, though they can also submit
> when an input submit button is pressed. Binding the ajax call to the submit
> events covers both scenarios, plus it seems to me a lot less complicated
> than catching the key13 event.
>
> Michel Belleville
>
>
> 2009/10/26 brian <zijn.digi...@gmail.com>
>>
>> Maybe something like this?
>>
>> $("#search").change(doSearch($(this))).bind("keypress", function(e) {
>>   if (e.keyCode == 13)
>>   {
>>      doSearch($(this));
>>      return false;
>>   }
>> });
>>
>> function doSearch(el)
>> {
>>   var vKeyword = el.val;
>>   $.ajax({
>>           type: "GET",
>>           ...
>>
>> On Sun, Oct 25, 2009 at 11:59 PM, cdukes77 <cduke...@bellsouth.net> wrote:
>> >
>> > I have the following syntax problem ...
>> >
>> >        $("#search").bind("keypress", function(e) {
>> >            if (e.keyCode == 13) return false;
>> >        });
>> >
>> >
>> >        $('#search').change(function() {
>> >            var vKeyword = document.getElementById('search').value
>> >            $.ajax({
>> >                type: "GET",
>> >                ...
>> >
>> > The first little bit of code traps for a user striking the enter key
>> > and cancels it (this prevents the page from submitting like a form).
>> >
>> > The second code snippet is the beginning of an AJAX script to get
>> > information based on a keyword value in a text field with an id of
>> > "search" which triggers when the change event fires.
>> >
>> > Both work perfectly ... but I would like to combine the two in such a
>> > way as to trigger the AJAX script on both/either the change event or
>> > the enter key - and still have the enter key NOT submit the page. I
>> > just can't figure out how to do it in a syntactically tidy way ...
>> > anybody have a suggestion?
>> >
>
>

Reply via email to