I have two js functions for the one same input (type="file"). They work by onclick attribute however when i click just for the second function, first one still works.. (Maybe beacuse of input changes..) I tried "return" or "break" to terminate but they didnt help. How can i terminate the function if it has finished its job.
■ HTML tags;
<input id="File1" type="file" name="galeri[]" accept="image/*" hidden="">
<label id="Label1" class="uploadProductPic" data-no="1" for="File1" onclick="myFunction(this)"><i class="fas fa-plus"></i></label>
and if i added a new picture codes below will be creating by myFunction
<div id="Picture1" onmouseover="mouseOnPic(this)" onmouseout="mouseOutPic(this)" class="ilanPreview d-flex justify-content-center">
<img src="img/pgiysi/pgiysi-44-2761428725-1.png" class="d-block" id="imgPicture1">
<div class="ilanPreviewEdit" hidden="true" data-edit="1" onclick="myEdit(this)"><i class="fas fa-edit"></i><div class="ilanPreviewEEText">Düzenle</div></div>
<div class="ilanPreviewErase" hidden="false" onclick="myErase(this)"><i class="fa fa-trash-o"></i><div class="ilanPreviewEEText">Sil</div></div>
</div>
■ First function is; (Creates a preview of image for the selected file from input and creates a new add input type="file")
var i = 1;
function myFunction(identifier) {
i++
no = $(identifier).data('no');
var loader = function(e) {
//content goes here
//create a preview of image
//add a new input file
}
var fileInput = document.querySelector("#File"+editNo);
fileInput.addEventListener("change", loader);
};
■ Second function is; (Jjust for the changing picture. If user clicks on the change button - that created on preview image before, so this function changes the preview of image.
function myEdit(identifier) {
var editNo = $(identifier).data('edit');
document.getElementById('File'+editNo).click();
var editor = function(e) {
//content goes here
//change the preview of image
return false; //After changing picture stop here and dont step to the first function again...
}
var fileInput = document.querySelector("#File"+editNo);
fileInput.addEventListener("change", editor);
};
When I click to change the picture, yes it changes but at the same time function add a new preview (same with selected one for the change and adds a new input file so i have 2 previews and 2 add buttons)