Sorry for this naive question , I am stuck here
I load my filters array from the server
var filters=["Color","Size","Quantity","Ram","Weight","Genre","Stock","Buypacks"];
Now here is the function when I add new filters, my goal is to add new filter value to above array:
function addfilter() {
var formData = new FormData($("#myform2")[0]);
var adfilter = $('#filter').val();
var xhr = new XMLHttpRequest();
xhr.open('POST', 'performfilterserver.php', true);
xhr.onload = function() {
if (xhr.status === 200) {
alert(xhr.responseText);
if (xhr.responseText.trim() == "filter added") {
if (!(filters.includes(adfilter))) {
filters.push(adfilter); //this never works
$('#filter').val("");
}
}
} else {
alert('An error occurred!');
}
};
// Send data
xhr.send(formData);
}
Here is the corresponding html:
<form id="myform2" method="post" enctype="multipart/form-data">
<div class="add_filters">
</select>
<label style="font-size:20px;"><b>Add filters:</b></label>
<input type="text" name="filter" id="filter" placeholder="Enter Here" style="border-style:solid;height:30px;" />
<label>Is this only required once while uploading?</label>
<input name="imagetf" type="checkbox" value="image" />
<button name="add_filter" type="button" onclick="addfilter()">ADD filter</button>
</br>
</br>
</div>
</form>
Any help will be appreciated
Edit: I am showing filter values in options through other function , but it shows the orignal array:
$.each(filters, function(key, value) {
var $option = $("<option/>", {
value: value,
text: value
});
$sel.append($option);
});