rvera / image-picker

Image Picker is a simple jQuery plugin that transforms a select element into a more user friendly graphical interface.
http://rvera.github.com/image-picker
Other
906 stars 216 forks source link

Getting the number of pictures that were selected #77

Closed NeedHelp001 closed 8 years ago

NeedHelp001 commented 8 years ago

Hi , may I know how do I get the number of pictures that were selected ? Thank you

ArmindoMaurits commented 8 years ago

$('#selectImage').data('picker').selected_values().length;

Where $('#selectImage') is my HTML <select> element with that ID.

NeedHelp001 commented 8 years ago

Thank you. May I know how am I going to get the id of the images selected and save it into the database. Currently, I am only able to save one id into the database , i am required to save multiple ids of the image selected.

ArmindoMaurits commented 8 years ago

You can just loop through the array and then foreach value in the array save it.. But that's back-end work.

$('#selectImage').data('picker').selected_values();

rvera commented 8 years ago

@ArmindoMaurits explained the client side of this.

To properly send multi values to a server you need to be careful with your naming, take a look at this http://stackoverflow.com/questions/11616659/post-values-from-a-multiple-select

ie, notice how it's named name="something[]" and not name="something"