I have a problem with my jQuery script and Safari (Mac + iPhone).
This is the structure of the page:
As I need to modify the data before sending it to the next script, I read all of the forms (serializeArray), modify it to my needs, write them in a new form (display:none) and let it send to the next page. This is the script:
$("input#newsubmit").click(function(e) {
e.preventDefault();
arraytix = [];
checkboxStatus = 0;
$("input[id^=field]").each(function(i) {
if ($(this).val() != 0) {
arraytix[i] = $(this).attr('name') + ":" + $(this).val() + ":" + $(this).parent().parent().find("li.four").find("input[id*=price_item]").val() + ":" + $(this).parent().parent().find("li.five").find("input[id*=vvk_item]").val();
}
});
var carttix = '';
jQuery.each(arraytix, function(i) {
if (arraytix.hasOwnProperty(i)) {
if (i == arraytix.length - 1) {
carttix += this;
} else {
carttix += this + '-';
}
}
});
$("form#finalSubmit").append( '<input name="cart" value="'+carttix+'" />');
$("form#finalSubmit").append( '<input name="versand" value="'+$("select#item_vat_1").val()+'" />');
$("form#finalSubmit").append( '<input name="barzahlung" value="'+checkboxStatus+'" />');
if (checkboxStatus == 0) {
var fields = $("fieldset.customer").serializeArray();
alert("before each");
jQuery.each(fields, function(i, field){
$("form#finalSubmit").append( '<input name="'+field.name+'" value="'+field.value+'" />');
alert("loop");
});
alert("after jquery.each");
}
//$("form#finalSubmit").submit();
}
The first instance of jQuery.each works as expected on all browsers and plattforms. The second instance of jQuery.each with the append command doesn't execute on Safari on all plattforms.
For debugging purpose I have added some alerts. Mac with Safari: alert("before each") and alert("after each") get triggered, jQuery.each doens't. Other browsers (including Firefox Mac) haven't got any problem. The first alert, some alert("loop")s and the last alert fire up as it should be.
What is the problem here?