I want to get a button ID onclick and apply it to another function. This is the code I have :
<button id="image-upload-button" onClick="reply_click(this.id)" data-link="<?php echo base_url().'admin/phones/upload_image/'; ?>" input-name="image" on-change="imageUpload(this.form);"></button>
and Javascript :
//get button id
function reply_click(clicked_id)
{
var button_id = clicked_id;
}
function reset() {
var input_name = $('#' + button_id).attr('input-name');
var on_change = $('#' + button_id).attr('on-change');
var input = $('<input name="'+ input_name +'" type="file" onchange="'+ on_change +'"/>').appendTo(form);
input.change(function(e) {
input.unbind();
input.detach();
btn.trigger('choose', [input]);
reset();
});
};
but, when I add $('#' + button_id) whole the script stops working. how can I fix it
button_idin the function scope. So it only exists within thereply_clickfunction. I think you meant to declare it in the global scope, outside of all functions.