Note that there are some explanatory texts on larger screens.

plurals
  1. POOnly allow to trigger event if checkbox is not checked
    primarykey
    data
    text
    <p>I have a table with a checkbox, when the user clicks on the checkbox, something is copied into a div, so the user knows what he has selected.</p> <p>However, if I uncheck and check again, then its copied again to the div.</p> <pre><code> //On every checkbow that is clicked var flag = false; $("#ctl00_PlaceHolderMain_myGrid input").change(function () { if (this.checked &amp;&amp; flag === false) { var jobCode = $(this).parent().parent().parent().find("td:eq(2)").text() var jobName = $(this).parent().parent().parent().find("td:eq(1)").text() var displayvalue = jobCode.toUpperCase() + " - " + jobName.toUpperCase(); //var removeDiv = $("#" + clientCode); //removeDiv.remove(); AddSelectedJob(jobCode, displayvalue); FillSelectedJobs(); } }); //Add selected job in the results div function AddSelectedJob(id, display) { //create a div for every selected job $("[id$=ResultsDiv]").append('&lt;div class="selectedjobs" id=' + id + '&gt;' + display + '&lt;a href="javascript:;" onclick="removeSelectedJob(this)"&gt;Remove selected job&lt;/a&gt;&lt;/div&gt;'); } //Removes the selected job from the resutls div function removeSelectedJob(el) { $(el).parent().remove(); } function FillSelectedJobs() { //save values into the hidden field var selectedJobs = $("[id$=ResultsDiv]").find("[class$='selectedjobs']"); var returnvalue = ""; for (var i = 0; i &lt; selectedJobs.length; i++) returnvalue += selectedJobs[i].id + ";"; $("[id$=HiddenClientCode]").val(returnvalue); } </code></pre> <p>This is the generated html</p> <pre><code>&lt;div&gt; &lt;div style="height: 300px; overflow: auto; float: left"&gt; &lt;div&gt; &lt;table cellspacing="0" cellpadding="4" id="ctl00_PlaceHolderMain_myGrid" style="color:#333333;width:100%;border-collapse:collapse;"&gt; &lt;tr style="color:White;background-color:#5D7B9D;font-weight:bold;"&gt; &lt;th scope="col"&gt;&amp;nbsp;&lt;/th&gt;&lt;th scope="col"&gt;JobCode&lt;/th&gt;&lt;th scope="col"&gt;JobName&lt;/th&gt;&lt;th scope="col"&gt;JobPartner&lt;/th&gt;&lt;th scope="col"&gt;JobManager&lt;/th&gt;&lt;th scope="col"&gt;ClientName&lt;/th&gt; &lt;/tr&gt;&lt;tr style="color:#333333;background-color:#F7F6F3;"&gt; &lt;td&gt; &lt;input id="ctl00_PlaceHolderMain_myGrid_ctl02_CheckBox1" type="checkbox" name="ctl00$PlaceHolderMain$myGrid$ctl02$CheckBox1" /&gt; &lt;/td&gt;&lt;td&gt;column1&lt;/td&gt;&lt;td&gt;column2&lt;/td&gt;&lt;td&gt;column3&lt;/td&gt;&lt;td&gt;column4&lt;/td&gt;&lt;td&gt;column5&lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/div&gt; &lt;/div&gt; &lt;div style="margin-top: 0px; margin-left: 10px; float: left"&gt; &lt;span&gt;Selected :&lt;/span&gt; &lt;div id="ResultsDiv" style="margin-top: 0px"&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>Update 1: A more clear explanation:</strong></p> <p>I have a table with checkboxes, when a row is selected the job code and job name is copied to a div called results. In that div, I created an anchor tag to remove the div itselft. When the remove selected job link is clicked, I should be able to add it again from the table when click the checkbox again. However if the selected job is already on the div results, I should not be able to add it again. Please see question here also: <a href="https://stackoverflow.com/questions/16891656/remove-div-on-the-click-of-a-link-that-was-created-dynamically">Remove div on the click of a link that was created dynamically</a></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.
 

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