Ambo100
Ambo100

Reputation: 1189

Insert text into the input/textarea using Jquery

<div class="ctrlHolder">
<label for="" id="name.label">Name</label>
<input name="name" id="name" type="text" class="textInput small" />
<p class="formHint">The name of the item you are submitting</p>
</div>

How can I insert predefined text into a input element. I'd like this function to active when the user doubleclicks the label element.

$('#name.label').dblclick(function(){
    $('#name').val('some text');
});

Upvotes: 4

Views: 37812

Answers (2)

Rafay
Rafay

Reputation: 31043

here check this fiddle

you can use .text("yourPreDefinedText") to replace the text of an element

Upvotes: 7

Colin O&#39;Dell
Colin O&#39;Dell

Reputation: 8657

$('#name.label') will cause jQuery to look for an element with id "name" and class "label". I believe the code above should work if you rename the label's id to something like "name-label".

Upvotes: 1

Related Questions