Anon
Anon

Reputation: 865

Assign a value to a input field via jquery

I want to change the value of an input field with jquery.

I generate the target id as follows:

var target_id = the_clicked_button.replace('_btn','');

var myValue = "sample";

I want to assign the value of myValue to target_id. Here's what I've tried out.

("#($( "target_id" ).val();)").val(myValue);

Upvotes: 0

Views: 43

Answers (1)

Try

$('#' + target_id).val(myValue);
//    ^ String Concatenation

Upvotes: 1

Related Questions