tags:

views:

33

answers:

4

Hi there, I need a little of your help here.

In my case I am having search textbox on b.php, in which user can enter username and hit enter to get the serched user-details. Ok this is so far. Now my search code to deal with database is ready in c.php and i want to call it through b.php with jquery's event. actuaully my a.php is home file and calling b.php through it on click event. Now flow for jquery will be like this a.php > b.php > c.php

There is no button to search, hitting enter key only will give searched user.

I writ my code in jquery as:

$(document).ready(function(){

    $('#srchtxt').bind('click', function(){ 
    if($('#srchtxt').val() != '') {
              $('#loading').html('<img src="images/ajax-loader(1).gif">');
              $('#loading').show(); 
              $.get('/usersearch.php?tnm3='+arr3, '', function(data){
                $('#content').html(data);
                $('#loading').hide();    
        });     
            }   
   });  
   $('#srchtxt').bind('keyup', function(e){               
       if(e.keyCode==13) {
           $("#srchtxt").trigger('click');       
       }    
   });   
});

This event is not working. can you help me here?

A: 

It is not working both on Firefox and IE.

For ie i think we have to use the following code to get the event

if(window.event) { window.event.keyCode }

gov
then look at this - [simple test case](http://jsfiddle.net/Dmx6Q/1/show) - [the codes](http://jsfiddle.net/Dmx6Q/1/)
Reigel
yes guys, getting it now, a small mistake caused this. One more query, is there any text change event in jquery, so instead of hitting enter, as he enter text he will get text related searches. as I am a newbie to jquery, don't know about it. I will really appreciate your help! Thank you in advance.
Rishi2686
A: 

Instead of .bind try to use .live() http://api.jquery.com/live/

Asif Mulla
+1  A: 

I think you mixed search field and search button.

The proper solution is folowing:

$('#srchtxt').keyup(function(e){               
       if(e.keyCode==13) {
           $("#search-submit").trigger('click');       
       }
});
$('#search-submit').click(function(){alert('button has been clicked')});

See working example here

Nik
A: 

I usually use event.which instead of event.keyCode It may be compatible with more browsers.

Plus, you mixed up some ID...

Chouchenos