I'm trying to make my textfields stack in descending order when adding a new textfield.
Here is my code:
JS:
var max_fields = 10; //maximum input boxes allowed
var wrapper = $(".input_fields_wrap"); //Fields wrapper
var add_button = $(".add_field_button"); //Add button ID
var x = 1; //initlal text box count
$(add_button).click(function(e){ //on add input button click
e.preventDefault();
if(x < max_fields){ //max input box allowed
x++; //text box increment
$(wrapper).append('<div><input type="text" class="form-control" name="mytext[]" placeholder="<Menu Name / Transaction ID/ Description>"/> <select><option ></option><option >Add</option></select><a href="#" class="remove_field"> Delete</a></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
I tried using the js sort method but that didn't work....
Thanks for help in advance!