Vwake
Vwake

Reputation: 171

get Value of Input tag using Jquery

<ul id="temp-list">
<li id="CommCheck" > Comm Check </li>
<input id="CommCheck-data" type="hidden" value="text1" />
....
</ul>


var vdata = $(ui.draggable).attr("id")+'-data'; /this gives me the CommCheck-data
alert(vdata); 
var text-data = $(vdata).val(); // should give me the value of Input id: "CommCheck-data"
alert(text-data); // but this states undefined ???

how do i get the input value ? am I doing something wrong ?

Upvotes: 1

Views: 7870

Answers (1)

David Tang
David Tang

Reputation: 93664

You need a "#" in front to tell jQuery it's an ID, not a tag name:

$("#" + vdata).val();

Also javascript variables cannot contain dashes in them. Try var textData.

Upvotes: 4

Related Questions