is this possible to achieve? I already get the value I wanted from ajax result but in second part I want THAT value to return from another event. Currently it returns ‘undefined’. Please see my code below. Any idea? Thanks in advance! 🙂
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'myURL.php',
data: dataString,
success: function (data) {
console.log(data);
var obj = $.parseJSON(data);
if(!$.isEmptyObject(obj))
{
$.each(obj, function(index, record) {
$('#updateRecord').append('<input type="text" id="regionDesc" value="' + record.firstValue + '"><button type="submit" id="submit" data-theme="b">Update</button>');
});
}
$("#update").click(function() {
var regionDesc= $("regionDesc").val();
console.log(regionDesc);
});
});
});
SOLUTION :
$(document).ready(function() {
$.ajax({
type: 'GET',
url: 'myURL.php',
data: dataString,
success: function (data) {
console.log(data);
var obj = $.parseJSON(data);
if(!$.isEmptyObject(obj))
{
$.each(obj, function(index, record) {
$('#updateRecord').append('<input type="text" id="myID" value="' + record.firstValue + '"><button type="submit" id="submit" data-theme="b">Update</button>');
});
}
$("#update").click(function() {
var myID= $("#myID").val();
console.log(myID);
});
});
});
change this
var regionDesc = $("regionDesc").val();to this
var regionDesc = $("#regionDesc").val();if you are using class attributes then this
var regionDesc = $(".regionDesc").val();