This is probably very easy, but I just can't figure out how to solve it right now. Each time a submit button is clicked, the function below checks input field 1 (name), and if not empty adds the value to an associative array, and continue with the description.
What I want is to add a new level 1 element to the array every click, that should hold these value, so that it after three clicks looks like this:
Click 1:
listObject[0]['listObjectName'] = 'Name 1';
listObject[0]['listObjectDesc'] = 'Desc 1';
Click 2:
listObject[1]['listObjectName'] = 'Name 2';
listObject[1]['listObjectDesc'] = 'Desc 2';
Click 3:
listObject[2]['listObjectName'] = 'Name 3';
listObject[2]['listObjectDesc'] = 'Desc 3';
The function:
$('#addListObjectSubmit').click(function (e) {
var listObjectName = $('#m_newListObject').val();
if((listObjectName == null) || (listObjectName == '')) {
return false;
}
else {
listObjects['listObjectName'] = listObjectName;
var listObjectDesc = $('#m_newListObjectDesc').val();
if ((listObjectDesc == null) || (listObjectDesc == '')) {
listObjects['listObjectDesc'] = null;
}
else {
listObjects['listObjectDesc'] = listObjectDesc;
}
}
e.preventdefault();
});
So, what is the best way of dealing with this?