RafaelM
RafaelM

Reputation: 159

Insert text in to Input Field using javascript

I am trying to insert text in to an input field using this code.

This is the code I am using:

<input class="cid" type="text" name="c1" />
<input class="cid" type="text" name="c2" />
<input type="button" value="Insert Text" onclick="insertAtCaret('c1','TEXTTOINSERT1');insertAtCaret('c2','TEXTTOINSERT2');" />

But nothing is happening. I don't know JS so I'm not sure if the JS code I referenced before is only for textareas which did work when I tested.

Thanks!

Upvotes: 0

Views: 187

Answers (1)

adeneo
adeneo

Reputation: 318202

The code in the link uses the ID of the element, so you'll have to add an ID :

<input class="cid" type="text" name="c1" id="c1" />
<input type="button" value="Insert Text" onclick="insertAtCaret('c1','TEXTTOINSERT');" />

FIDDLE

Upvotes: 3

Related Questions