$(document).ready(function(){ $('.product_set').change(function(event){ setChange('product_form'); }); setChange('product_form'); $('#store_photo_div').magnificPopup({ delegate: 'a', type:'image', //gallery:{ //enabled:true //} }); }); function setChange(form_name){ var form = document.getElementById(form_name); var form_data = formData2QueryString(form); //console.log(form_data); $.ajax({ url: gBaseURL+'store/item/set_change.html', data: form_data, success: function(data){ setChangeReturn(data); }, error:function(jqXHR,textStatus, errorThrown){ alert('failure'); alert(errorThrown); }, type: "POST", dataType: "json" }); } function setChangeReturn(myObject){ //console.log(myObject); if(myObject.error == undefined || myObject.error == 1){ alert(myObject.message); }else{ //price range section if(myObject.max_price != undefined){ max = parseFloat(myObject.max_price)}else{ max = 0}; if(myObject.min_price != undefined){ min = parseFloat(myObject.min_price)}else{ min = 0}; if(!(max == 0 && min == 0)){ range = ''; if(max > min){ range = range + "$" + min.toFixed(2) + " - $" + max.toFixed(2); }else{ range = range + "$" + min.toFixed(2); } $('.discount-display').html(range); } options = myObject.options; $('.product_set').each(function(){ //get setid id = this.id; //console.log(id); var selected_val = $(this).val(); console.log(selected_val); set_options = options[id]; //console.log(options[id]); if(set_options == undefined){ set_options = []; alert('undefined options'); } $(this).empty().append(''); var length = set_options.length; //console.log(length); var element = null; for (var i = 0; i < length; i++) { element = set_options[i]; attribute_text = ''; if(element['instock'] <= 0){ attribute_text = attribute_text + ' disabled="disabled"'; element['display'] = element['display'] + ' Out Of Stock'; } if(element['value']==selected_val){ attribute_text = attribute_text + ' selected="selected"'; } option_text = ''; $(this).append(option_text); } }); } } function checkSubmit(form_name){ var form = document.getElementById(form_name); var ajax = new Ajax(); var form_data = formData2QueryString(form); alert(form_data); //retrieve field => value from string; var attributes = new Array(); while(form_data.length > 0){ if(form_data.indexOf('&') == 0){ //remove & form_data = form_data.substring(1); } if(form_data.length > 0){ if(form_data.indexOf('&') != -1){ attributes.push(form_data.substring(0, form_data.indexOf('&'))); form_data = form_data.substring(form_data.indexOf('&')); }else{ attributes.push(form_data); form_data = ''; } } } alert(attributes); return false; } function checkSubmitReturn(str){ alert(str); var myObject = JSON.parse(str); if(myObject.error == undefined || myObject.error == 0){ return true; }else{ alert(myObject.message); return false; } }