I'm using the following code to create file upload inputfields and it works perfectly.
however, I need to rename them like so:
mytext[1]
mytext[2]
mytext[3]
etc etc...
so I did simply put var i = 0; and then I put the i++ in the code. when I alert the i I get 1,2,3 etc in the alert box so I know that works.
but this line is wrong and I cannot figure out how to use the i variable in this line:
<div><input type="file" name="mytext[i]"/></div>
and this is the entire code:
<script>
$(document).ready(function() {
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 i = 0;
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
i++
$(wrapper).append('<div><input type="file" name="mytext[[i]]"/></div>'); //add input box
}
});
$(wrapper).on("click",".remove_field", function(e){ //user click on remove text
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
</script>
and the HTML code:
<div class="input_fields_wrap">
<button class="add_field_button">Add More Photos</button>
<div><input type="file" name="mytext[]"/></div>
</div>
could someone please advise on this?
Thanks