javascript - how to use a form and controller to store inputs -
i'm working on web app i'm stuck on deleting elements have created.
i'm using jquery display thumbnail pictures , i'm trying include hovering x top right corner on-click delete thumbnail , original file upload before sending form.
this code:
$(document).ready(function() { // create thumbnail: $('#uploadimage').on('change', function() { resizeimages(this.files[0], function(dataurl) { $('#photo1').val(dataurl); document.getelementbyid("uploadpreview").src = dataurl; }); }); // attempting delete it: $('.hiddenimages .close').on('click', function() { var id = $(this).closest('.hiddenimages').find('img').data('id'); alert('remove picture: ' + id); document.getelementbyid(".hiddenimages").remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="pictureholders"> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview" data-id="photo-1" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview2" data-id="photo-2" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview3" data-id="photo-3" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview4" data-id="photo-4" style="width: 100px; height: 100px;" /> </div> </div> <div class="inputs"> <div> photo 1: <input type="text" id="desc1" name="desc1" /> <input id="uploadimage" type="file" /> </div> <input type="hidden" class="photos" id="photo1" name="photo1" value="" /> <br/> <div> photo 2: <input type="text" id="desc2" name="desc2" /> <input id="uploadimage2" type="file" /> </div> <input type="hidden" class="photos" id="photo2" name="photo2" value="" /> <br/> <div> photo 3: <input type="text" id="desc3" name="desc3" /> <input id="uploadimage3" type="file" /> </div> <input type="hidden" class="photos" id="photo3" name="photo3" value="" /> <br/> <div> photo 4: <input type="text" id="desc4" name="desc4" /> <input id="uploadimage4" type="file" /> </div> <input type="hidden" class="photos" id="photo4" name="photo4" value="" /> <br/> </div> any appreciated.
you trying handle identifier using class name inside getelemlementbyid
you should able remove container of clcked x, similar this: $(this).closest('.hiddenimages').remove();
in addition selector click event on x might need change removing container binding , such new .hiddenimages container not have click event bound.
you might need update $('.hiddenimages .close').on('click', function... $('.pictureholders').on('click', '.hiddenimages .close', function...
$(document).ready(function() { // create thumbnail: $('#uploadimage').on('change', function() { resizeimages(this.files[0], function(dataurl) { $('#photo1').val(dataurl); document.getelementbyid("uploadpreview").src = dataurl; }); }); // attempting delete it: $('.pictureholders').on('click', '.hiddenimages .close', function() { $(this).closest('.hiddenimages').remove(); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <div class="pictureholders"> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview" data-id="photo-1" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview2" data-id="photo-2" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview3" data-id="photo-3" style="width: 100px; height: 100px;" /> </div> <div class="hiddenimages"> <span class="close">×</span> <img id="uploadpreview4" data-id="photo-4" style="width: 100px; height: 100px;" /> </div> </div> <div class="inputs"> <div> photo 1: <input type="text" id="desc1" name="desc1" /> <input id="uploadimage" type="file" /> </div> <input type="hidden" class="photos" id="photo1" name="photo1" value="" /> <br/> <div> photo 2: <input type="text" id="desc2" name="desc2" /> <input id="uploadimage2" type="file" /> </div> <input type="hidden" class="photos" id="photo2" name="photo2" value="" /> <br/> <div> photo 3: <input type="text" id="desc3" name="desc3" /> <input id="uploadimage3" type="file" /> </div> <input type="hidden" class="photos" id="photo3" name="photo3" value="" /> <br/> <div> photo 4: <input type="text" id="desc4" name="desc4" /> <input id="uploadimage4" type="file" /> </div> <input type="hidden" class="photos" id="photo4" name="photo4" value="" /> <br/> </div>
Comments
Post a Comment