I am trying to dynamically check and uncheck a box with jquery.
The ideal situation would be that if you clicked on the editing project file, it would indicate that the field for loading a new image (edit_project_image) was active, that is, it would not be deleted by a single click on (edit_project_image) , or by clicking on (remove_edit_image) . In addition, if there is strikethough, so that I add that the remove_project_image class will be added, the checkbox will also be checked.
The idea is that any of the above is true, the current active image needs to be deleted.
Here is my jquery right now:
//show hide the file box to edit images $('.edit_project_file').live('click',function() { $(this).parent().next().toggle(); $(this).parent().removeClass("remove_project_image"); return false; }); //allow the user to remove the file box if they don't wish to edit an image $('.remove_edit_image').live('click',function() { $(this).parent().hide(); $(this).parent().removeClass("remove_project_image"); return false; }); //add strikethough when the user decides to delete an image $('.remove_project_file').live('click',function() { $(this).parent().toggleClass("remove_project_image"); $(this).parent().next().hide(); return false; });
Here is the HTML markup:
<ul class="imgPreview"> <li> <a href="#" rel="../images/portfolio/project_images/manager_pimg3_7_1281126121.jpg">manager_pimg3_7_1281126121.jpg </a> <a href="#" class="edit_project_file"> <img src="images/edit.gif"/></a> <a href="#" class="remove_project_file"> <img src="images/delete.gif"/></a> </li> <li class="edit_project_image"> <input name="upload_project_images[]" type="file" /> <a href="#" class="remove_edit_image" border="0"> <img src="images/delete.gif" /></a> </li> <li> <input name="edit_image[]" type="checkbox" value="manager_pimg3_7_1281126121.jpg" class="edit_image_checkbox"/> </li> </ul>
I believe a better situation would set var if true set the checkbox value to true. Things I've tried include:
$('.remove_project_file').live('click',function() { $(this).parent().toggleClass("remove_project_image"); $(this).parent().next().hide(); if ($(this).parent().next(".edit_image_checkbox").is(":not(:checked)")){ $('.edit_image_checkbox').attr('checked',true); } return false; });
This works in the sense that it checks all (above in the php loop) flags with the .edit_image_checkbox class, and not just the one next to the remove_project_file class that was clicked. Also do not uncheck the link when the link is checked again for this, I tried else {$('.edit_image_checkbox').attr('checked',true);} , it just confuses him, because he says that if it is not installed, check it, and then if it is installed, clear the check box.
Another idea I used was to use a variable and set it to true or false, and if true, then the checkbox is checked. I tried this as:
var file_checkbox_checked = false; if(file_checkbox_checked == true){ $('.edit_image_checkbox').attr('checked',true); } else{ $('.edit_image_checkbox').attr('checked',false); }
Then added file_checkbox_checked = true; to each of the functions that should check the box. It seemed to do nothing. I could set var file_checkbox_checked = true; , and this will check all the checkboxes with another problem, since there is no way to uncheck the box.
I am still involved in the training, thinking over part of this part of the project, so if you have any ideas, they will be great.