0

I'm fairly new to jQuery and would really appreciate some help with the following:

I've got an input form that allows user to select 3 different geo regions (country, region and city) All information comes from an API. I'd need the input from country (as the user types) to go into the URL that makes the call to the API for "city". This way the user gets only the cities relevant to the country.

This is what I have:

<input type="text" name="country" id="country" />
<input type="text" name="city" id="city" />

$(document).ready(function() {
        $("#country").tokenInput("http://someurl.com/search?q=", {
            method: "POST",
            searchDelay: 0,
        });

        $("#city").tokenInput("http://someurl.com/search?q=[Insert values form country input field]", {
            method: "POST",
            searchDelay: 0,
        });
    });

The jQuery plugin I'm using: this.

2
  • you are using a plugin , would need to research the API docs for the plugin on how to add data. Post a link to plugin docs Commented Nov 2, 2012 at 3:31
  • Hi @charlietfl thanks for that. Here the link to the plugin: loopj.com/jquery-tokeninput Commented Nov 2, 2012 at 3:34

1 Answer 1

1

I don't see it documented but the source of the plugin code allows a function to be used for the url option.

This should work:

$("#city").tokenInput(function(){
      return 'http://someurl.com/search?country='+ $('#country').val() +'q=';
     }, {
      method: "POST",
      searchDelay: 0,
});

If it gives you any problem, inspect the request in a browser console to see what the final url generated is, or see if any errors are thrown

Sign up to request clarification or add additional context in comments.

1 Comment

you might go the feature/bug tracker and mention this could be documented...I may have missed it in docs, but I don't think it's there

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.