0

I want to type kappa in input on image click. I have this code but it seems like it doesn't work...

document.getElementById("kappa").addEventListener('click', function () {
    var text = document.getElementById('usermsg');
    text.value = (text.innerHTML + ' kappa ');
});
<a href="#" id="kappa"><img src='http://placehold.it/50x50' width='100px'></a>
<br>
<input type="text" id="usermsg">

Where did I made a mistake? And how can I solve it?

2 Answers 2

3

Use value instead of text:

document.getElementById("kappa").addEventListener('click', function () {
    var text = document.getElementById('usermsg');
    text.value = (text.value + ' kappa ');
    return false;
});

And give a return false to make it not follow the link.

Fiddle: http://codepen.io/anon/pen/QjELxJ

Sign up to request clarification or add additional context in comments.

Comments

0

do the following:

    document.getElementById("kappa").addEventListener('click', function(evt) {
        document.getElementById("usermsg").value = "kappa";
    });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.