I've created a .post form that returns a JSON string and I need to get the data based on the name of the select boxes. please refer to the following example.
JavaScript
$(document).ready(function(){
$.post('/seller/product_upload/helpers/jpost_product_form_autofill.php',{product_id:$("input[name='product_id']").val()},function(data){
alert(data);
if(data!='false'){
var obj = jQuery.parseJSON(data);
$("#attributes_table select").each(function(){
var select=$(this);
select.find("option").each(function(){
var option=$(this);
var select_name=select.attr('name');
alert(select_name);
alert(obj.select_name);
if(option.val()==obj.select_name){
option.attr('selected','selected');
}
});
});
}
});
});
The main section of concern here is actually the bottom if part. obj.select_name is not the main object name here. It is actually the name of the selectbox which I had made it coincidental to my array key values parsed in JSON.
But now the system keeps alerting undefined for obj.select_name. Is there any way in which i can parse select_name as a string first before having it parsed as a JSON object?