-3

I have an input:

<input type="text" value="value" id="textinput" />

and a picture:

<img src="folan.png" value="hi" id="hi" />

I want that when I click the image it adds text to the input value. How I can accomplish this with PrototypeJS or pure JavaScript?

I tried this code:

document.getElementById("hi").addEventListener('click', function () {
    var text = document.getElementById('textinput');
    text.text = (text.text + ' after clicking');
});
cookie monster
  • 10,671
  • 4
  • 31
  • 45
mrna3r
  • 11
  • 5

1 Answers1

0

I'm not sure what you're trying to do here:

var text = document.getElementById('ar text = ');

But ar text = isn't an element's id. Maybe you meant this?:

var text = document.getElementById('textinput');

Additionally, you don't want to set the text property on an input element, you want to set its value:

text.value = (text.value + ' after clicking');

Example

David
  • 208,112
  • 36
  • 198
  • 279