javascript - Dynamically assign variable to jquery autocomplete query string -


i'm coding form user can submit playlists. there 'artist' field , 'song' field. both input type 'text'.

i'm attempting use jquery's autocomplete functionality in both fields. autocomplete results artist functions of user-keystrokes , autocomplete results songs functions of user-keystrokes , value of artist input field.

autocomplete seems work populate list of suggestions under artist input field. search.php script reading query string.

$(".artist").autocomplete("searchdev.php?type=artist&"+mydate.gettime(), {     width: 180,     selectfirst: false }); 

in search.php, var_export of $_get in searchdev.php after a keystroke yields

array (   'type' => 'artist',   1367531572213 => '',   'q' => 'a',   'limit' => '10',  'timestamp' => '1367531576911', ) 

this fine. however, when try supply variable query string(here window.sartist) in autocomplete(for song input field),

    $(".song").autocomplete("search.php?type=song&sartist="+window.sartist+"&"+mydate.gettime(),      {     width: 180,      selectfirst: false });  

sartist not defined correctly, ie var_export($_get) in search.php yields

array (   'type' => 'song',   'sartist' => '[object htmlinputelement]',   1367525807081 => '',   'q' => 'a',   'limit' => '10',   'timestamp' => '1367526169637', ) 

if global variable, not attached window used in place of window.sartist in query string, var_export($_get) yields

array (   'type' => 'song',   'sartist' => '',   1367528252501 => '',   'q' => 'a',   'limit' => '10',   'timestamp' => '1367528260585', ) 

so suspect query string cannot modified after loaded. have viable workaround allow variables dynamically assigned autocomplete query string? need 'song' autocomplete suggestions contingent upon value of 'artist' field.

you need use function source pass multiple dynamics params query :

$('.song').autocomplete({    var value = $(this).val();      source:function( request, response ) {           $.getjson( "searchdev.php", {             term: value ,               data:{                   type:"song",                   myparam:$('#myparam').val()               }           }, response );    } }) 

in example, if current input .song have value 'high hope' , #myparam field have value "pink" query looks : searchdev.php?term=high+hope&type=song&myparam=pink

fiddle (no real data source, see console) : http://jsfiddle.net/rfubp/3/ doc source option of jquery autocomplete : http://api.jqueryui.com/autocomplete/#option-source

ps : in code, sure window.sartist returns value , not element ?


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -