Get value from id and pass in input field

I’m trying to get the id from an image by clicking on it to store the id name as value in an input field.

Well, this works:


    var key = $(this).attr("title");


2 thoughts on “Get value from id and pass in input field”

  1. see my variant:

    <img src='myimg.jpg' id='my_id'>
    <button onclick='paste_id()'>click me</button>
    <input type='text' id='my_input'>
    function paste_id(){
        let id_text = document.getElementById("my_id").getAttribute('id');
        let input = document.getElementById("my_input");
        input.value = id_text;

Leave a Comment