views:

25

answers:

1

I am trying to implement this jQuery auto complete function but the problem is this i need the value of the previous input field. getting the value from the previous is easy, I just dont know how to add it to the call

the call for the previous value is on top of the document.ready and this doesnt get called when the user types

I NEED to pass it in with this serviceurl like this

song_path(value) 

but that fails

    $(document).ready(function(){
            value = $('#request_artist').val();
        $('#song_artist').autocomplete({
          serviceUrl: '<%= song_path() %>',
          minChars:1,
          width: 300,
          delimiter: /(,|;)\s*/,
          deferRequestBy: 0, //miliseconds
          params: { artists: 'Yes' },
        });
    });

So i basically need something like this

    $(document).ready(function(){
        $('#song_artist').autocomplete({
          serviceUrl: '<%= song_path() %>'$('#request_artist').val(),
          minChars:1,
          width: 300,
          delimiter: /(,|;)\s*/,
          deferRequestBy: 0, //miliseconds
          params: { artists: 'Yes' },
        });
    });

but this fails

+1  A: 

You will not be able to use song_path helper, as it is rendered before getting to the browser, you can't call that function in the browser. Instead you need to write something like

serviceUrl: '/songs/' + $('#request_artist').val(),   

if $('#request_artist').val() returns the id.

nathanvda