Reputation: 47
I'm currently working on an ajax call that will update the value of a textbox:
<div id="PNIncrementDiv" style="position:absolute; left: 730px; top: 15px; width: 350px;" class="">
<input id="TBIncrementTextBox" class="textbox" type="text" style="position:absolute; top:25px; left: 75px; width: 60px; height: 40px;" runat="server" />
</div>
My ajax function, which returns an integer, and Is tested to be returning the correct answer is below:
getIncrement: function (id) {
$.ajax({
url: "<%=Session("BaseUri")%>" + '/handlers/DataEntry/SPC_InspectionInput.ashx',
type: 'GET',
data: { method: 'getIncrement', args: { IncrementId: id} },
success: function (data) {
console.log(data);
Inc_Num = data;
$('#TBIncrementTextBox').val(data.toString());//nothing happens!
},
error: function (a, b, c) {
alert(c);
}
});
}
However, when I try to change the value of the textbox, nothing happens. What am I doing wrong?
Upvotes: 2
Views: 1895
Reputation: 343
try to use value method
$('#TBIncrementTextBox')[0].value = data.toString()
getIncrement: function (id) {
$.ajax({
url: "<%=Session("BaseUri")%>" + '/handlers/DataEntry/SPC_InspectionInput.ashx',
type: 'GET',
data: { method: 'getIncrement', args: { IncrementId: id} },
success: function (data) {
console.log(data);
Inc_Num = data;
$('#TBIncrementTextBox')[0].value = data.toString();//nothing happens!
},
error: function (a, b, c) {
alert(c);
}
});
}
Upvotes: 2
Reputation: 42
Try targeting the input box using $('#PNIncrementDiv input').val(data.toString());
If that works, your ASP.NET script is most likely altering your target input's ID
Upvotes: 0