Reputation: 77
Hi I'm not very good at explaining this in the right terms but I'm trying to retrieve the value of a textbox. The textboxes are in a table and each row has one and the id of each is made up of a unique id and a name... html
<label id="labelref<?php echo $row_list['pp_order_details_id']; ?>" name="labelref<?php echo $row_list['pp_order_details_id']; ?>"></label>
<input type="text" id="save<?php echo $row_list['pp_order_details_id']; ?>" name="saveref<?php echo $row_list['pp_order_details_id']; ?>" style="margin-right:5px;" />
<a href="javascript:saveref('<?php echo $row_list['pp_order_details_id']; ?>');" id="aref<?php echo $row_list['pp_order_details_id']; ?>" style="margin-right:5px;">Save</a>
<label id="errorref<?php echo $row_list['pp_order_details_id']; ?>" style="color:red; margin-right:5px;"></label>
javascript/jquery
function save(order_id) {
var newSaveRef = "saveref"+order_id;
var saveref = $('#newSaveRef').val();
alert(saveref);
}
I want the value of save ref. If this value ($row_list['pp_order_details_id'];) is SS16363 then this value (newSaveRef) should be saverefSS16363.
but how do I get the value from the textbox with that ID????
Upvotes: 1
Views: 388
Reputation: 1448
try this one
var saveref = $('#saveref' + order_id + '' ).val();
Upvotes: 0
Reputation: 35572
function save(order_id) {
var newSaveRef = "saveref"+order_id;
var saveref = $('#'+newSaveRef).val();
alert(saveref);
}
Upvotes: 1
Reputation: 6359
function save(order_id) {
var newSaveRef = "#saveref"+order_id;
var saveref = $(newSaveRef).val();
alert(saveref);
}
You were using a string literal rather than the variable itself.
Upvotes: 2
Reputation: 136124
newSaveRef
is a variable, so concatenate it with a hash #
to use the variable to find an element with that id.
var saveref = $('#' + newSaveRef).val();
Upvotes: 3