Reputation: 659
I am trying to pick the value from the text box.
Text box id data-id data-phase data-project is dynamically generated.
<input class="addinformation" type="text" data-id="" data-phase="1_2" data-project="1" value="" style="width: 50%;" id="IMxyz_addinfo">
My js code is
var TktNo ="IMxyz";
Method 1:
console.log($(".additionalInfoBox").find("[data-id='" + TktNo + "']").html());
Method 2
console.log($("#" + TktNo + "_addinfo").val());
Both are failing....any idea
console.log("1 " + $(".addinformation").val());
console.log("2 " + $(".addinformation").find("[data-id='" + TktNo + "']").val());
console.log("3 " + $("#" + TktNo + "_addinfo").val());
console.log("4 " + $('input#' + TktNo + '_addinfo').val());
output is
1
2 undefined
3
4
when i do console.log($(".addinformation"));
following are the snap shot
Upvotes: 0
Views: 266
Reputation: 1650
Use this.
console.log($("input.addinformation").val());
Or
var TktNo ="IMxyz";
console.log($("input#" + TktNo + "_addinfo").val());
Upvotes: 1
Reputation: 926
I've coded it on jsfiddle: http://jsfiddle.net/ZggHZ/. (Used alert just to test)
var TktNo ="IMxyz";
alert($('input.addinformation#'+TktNo+'_addinfo').val()
);
Upvotes: 3
Reputation: 762
What are you doing here ? The class of your input field is addinformation
and in your first method you are using some other class (additionalInfoBox) to select the element. It wont work. If there is only one input with the class addinformation
, then this should work :
console.log($(".addinformation").val());
Upvotes: 1
Reputation: 51
console.log($("#" + TktNo + "_addinfo").val());
should return the value. make sure this is called after the html is rendered.
Upvotes: 1