Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>What's wrong with this:</p> <pre><code>window.open("graph.php?mach_id=" + machineId); </code></pre> <p>If the (unexplained) problem is that you need to save the value of <code>machineId</code> at the time the <code>ondblclick</code> handler is <em>defined</em> rather than using its value at the time the handler is <em>executed</em>, you need a closure:</p> <pre><code>(function (id) { rect.node.ondblclick = function() { window.open("graph.php?mach_id=" + id); } })(machineId); </code></pre> <p><strong>UPDATE:</strong> OK, based on the new code you posted I can see I was on the right track with the closure idea above. The problem is that your event handlers try to use the <code>i</code> index at some point in the future at which time <code>i</code> equals whatever value it had when the loop ended. You need something like this:</p> <pre><code>function showUtilization(machineId, rectUtil, txtResult, txtMCName, rectCover) { for (var index = 0; index &lt; machineId.length; index++) { (function(i){ $.ajax({ // all of your other code here, where anytime it // uses i it will be using the parameter of the // anonymous function rather than the loop counter // (which I've renamed to "index" to avoid confusion // with "i") }); })(index); } } </code></pre> <p>I've changed the loop to use a counter called <code>index</code>, which is passed in to an anonymous function that is immediately executed. Your existing code, i.e., everything that you have inside the <code>$.ajax({ });</code> call goes inside that anonymous function. When your success and ondblclick handlers are executed at some point in the future they will use the <code>i</code> from their own closure rather than the loop index. </p>
    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.
    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