Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery select in each element
    primarykey
    data
    text
    <p>HTML:</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;title&gt;test&lt;/title&gt; &lt;script type="text/javascript" src="http://code.jquery.com/jquery-1.10.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript" src="test.js"&gt;&lt;/script&gt; &lt;style type="text/css"&gt; .green { color: #0C0; } .red { color: #F00 } &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;div id="main"&gt; &lt;form method="post" action="post.php"&gt; &lt;input type="submit" value="OK" /&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data1" value="1" /&gt; &lt;label for="data1"&gt;Data 1&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data2" value="2" /&gt; &lt;label for="data2"&gt;Data 2&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data3" value="3" /&gt; &lt;label for="data3"&gt;Data 3&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data4" value="4" /&gt; &lt;label for="data4"&gt;Data 4&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data5" value="5" /&gt; &lt;label for="data5"&gt;Data 5&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data6" value="6" /&gt; &lt;label for="data6"&gt;Data 6&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data7" value="7" /&gt; &lt;label for="data7"&gt;Data 7&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data8" value="8" /&gt; &lt;label for="data8"&gt;Data 8&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data9" value="9" /&gt; &lt;label for="data9"&gt;Data 9&lt;/label&gt; &lt;/div&gt; &lt;div class="content"&gt; &lt;input type="checkbox" name="data" id="data10" value="10" /&gt; &lt;label for="data10"&gt;Data 10&lt;/label&gt; &lt;/div&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>test.js:</p> <pre><code>$(document).ready(function() { $("#container #main form").submit(function(e) { e.preventDefault(); $(this).find(".content").each(function() { $_this = $(this); if ($(this).find("input[name=data]").is(":checked")) { $data = $(this).find("input[name=data]").val(); $.ajax({ url: "post.php", type: "POST", data: { data: $data }, success: function(data) { if (data = true) { $_this.addClass("green"); } else { $_this.addClass("red"); } } }); } }); }); }); </code></pre> <p>post.php</p> <pre><code>&lt;?php if (isset($_POST["data"])) return true; else return false; ?&gt; </code></pre> <p><a href="http://jsfiddle.net/8yQv4/" rel="nofollow">http://jsfiddle.net/8yQv4/</a></p> <p>When I click on the submit button, if the server returns results the "success", elements has contains that will addClass("green"). On the contrary, it will addClass("red")</p> <p>Please help me... Thank you!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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