Find the closest checked checkbox value
<p>I have a list of products with prices, before the productname I have a checkbox. What I want is when I checked a checkbox the price must show up in the table.</p>

<p>The products are fetched by a loop from MySQL.</p>

<p>This is my code for a better view:</p>

<pre><code>&lt;?
    $query = "SELECT upgrades.upgrade_name, upgrades.upgrade_id, upgrades.volgorde, upgrades.price
            FROM upgrades
            LEFT JOIN upgrades_to_products
            ON upgrades.upgrade_id = upgrades_to_products.upgrade_id
            WHERE upgrades_to_products.product_id = 20
            AND status = 1
            ORDER BY upgrades.volgorde";
    $sql = mysql_query("$query");
    while ($fill = mysql_fetch_array($sql)) {
        $upgrade_id = $fill['upgrade_id'];
        $upgrade_name = $fill['upgrade_name'];
        $price = $fill['price'];

        $name = str_replace(' ', '_', $upgrade_name);
        $name = strtolower($name);
        echo '
        &lt;tr class="'.$class.'"&gt;                         
            &lt;td&gt;
                &lt;input id="'.$name.'" name="'.$name.'" type="checkbox" value="'.$price.'" /&gt;
            &lt;/td&gt;
            &lt;td&gt;
                &lt;a href="http://www.informer.nl/modules/?ID='.$_GET['ID'].'&amp;upgrade_id='.$upgrade_id.'" target="_blank"&gt;'.$upgrade_name.'&lt;/a&gt;
                &lt;a href="http://www.informer.nl/modules/?ID='.$_GET['ID'].'&amp;upgrade_id='.$upgrade_id.'" target="_blank"&gt;
                    &lt;img src="images/vraag.jpg" border="0" style="margin-left:5px;" /&gt;
                &lt;/a&gt;
            &lt;/td&gt;
            &lt;td align="right"&gt;&amp;euro; '.sprintf('%01.2f', $price).'&lt;/td&gt;                         
            &lt;td align="right"&gt;&lt;div class="module_value"&gt;&lt;/div&gt;&lt;/td&gt;                         
        &lt;/tr&gt;';
    }
?&gt;
</code></pre>

<p>You can see the checkbox between the first <code>&lt;td&gt;&lt;/td&gt;</code>. So when I checked one of the checkboxes that value must show up in the <code>&lt;div class="module_value"&gt;&lt;/div&gt;</code>.</p>

<p>I tried something like this:</p>

<pre><code>$("input[type=checkbox]").click(function() {
    var module_price = $("input[type=checkbox]").val();
    $(".module_value").text(module_price.toFixed(2));
});
</code></pre>

<p>but that didnt work so I hope someone can help me out.</p>

<p>Thanks in advance!</p>
