Is there a way to read data from a CartoDB infowindow and write it, e.g. into a form?

For example: In a city plan with parcels, the user clicks on a parcel and the infowindow opens with information on this parcel. Now I think about a “Fill in” button that allows writing the attributes of the parcel selected into a form.

Any hints?

1 Answer 1


I've prepared an example for you. You can check it here (and full page)

The "trick" is to capture the infowindow's data. Infowindow is a Backbone Model, so I worked with its bind method.

.done(function(vis, layers) {
      lyr = layers[1];
      lyr.infowindow.bind('change', function() {
        if ((lyr.infowindow.attributes.content.fields !== undefined) && (lyr.infowindow.attributes.content.fields[4] !== undefined)) {
          country = lyr.infowindow.attributes.content.fields[4].value;
          pop2005 = lyr.infowindow.attributes.content.fields[7].value;
          document.getElementById("inpCountry").value = country;
          document.getElementById("inpPop").value = pop2005;

Also, in this example, I'm filling a form with data, as you requested in your post.

  • Great example! Muchas gracias!
    – Flo
    Commented Mar 12, 2015 at 15:50

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.