Note that there are some explanatory texts on larger screens.

plurals
  1. POAccessing particular instance of variable from for loop ( scope issue?)
    primarykey
    data
    text
    <p>Pretty new to any kind of programming, so sorry if this is a mess! I have a chloropleth map where the colors are determined by a slider, and that's working fine. BUT, I need to display the value that gets used to determine the color in a text field when each specific shape on the map is clicked - and have that still update when the slider is used. </p> <p>I can get it to calc properly for the area inside the click, but then it doesn't update with slide, so i think i need it outside the click, and then just some show/hide on click. But outside of the click, I have no "this" to reference and can't get at the iteration I need. I've been trying every possible thing I come across, and am now totally lost. </p> <p>Couldn't thank you enough for any help/explanation.</p> <p>What I've got is:</p> <pre><code>function fromslide(){ // Set properties for each county. for (var i=0; i &lt; counties.length; i++) { ctys = counties[i]; //console.log (ctys); var id = ctys.data("id"); alloc= ((parseInt(Landvar[id].val) * landweight) + (parseInt(Popvar[id].val) * popweight) + (parseInt(Poorvar[id].val) * poorweight)); console.log(alloc); // Set county color. ctys.attr({ fill: getColor(alloc/ 1000000), }); //console.log (selectedcnty); console.log (window.selectedcnty); //this is what's not working if (selectedcnty = String(id)) { thisalloc = ((parseInt(Landvar[id].val) * landweight) + (parseInt(Popvar[id].val) * popweight) + (parseInt(Poorvar[id].val) * poorweight));} $("#allocfield").val(thisalloc); ctys.click(function() { for (var i=0; i &lt; counties.length; i++) { var ctys = counties[i]; var id = ctys.data("id"); ctys.attr({stroke: "#fff" }); }; this.toFront(); this.attr({stroke: "orange" }); var name = this.data("id"); $("#namefield").val( Popvar[name].name); $("#popfield").val( Popvar[name].val); $("#landfield").val( Landvar[name].val); $("#poorfield").val( Poorvar[name].val); console.log(thisalloc); window.selectedcnty = name; console.log (window.selectedcnty); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload