javascript - Jquery select dropdowns (array) option on change get value from div class -


i have multiple select dropdowns , multiple divs same class. each div have 1 dropdown , 1 div class .dz-filename.

by uploading image > filename text come div class .dz-filename , image can choose format. want link image format, based on selection.

how can text inside div class .dz-filename , fill text option value?

after submitting form, want use php see format linked image

for example:

$(document).ready(function() {      $(".dz-select-system").change(function(){         var filename = $(".dz-filename span").text();  alert(filename);      });  });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>  <div id="file_upload_container" class="dropzone dz-clickable dz-started dz-max-files-reached">  <div class="upload">  <div class="dz-filename">  <span data-dz-name="">banner.jpg</span>  </div>  <input type="hidden" class="picture_upload" name="picture_upload[]">  <select class="dz-select-system" style="width: 100%;margin-top: 10px;" name="format[]">  	<option selected="" disabled="" value="-1">selecteer uw formaat</option>  	<option value="{here filename if option select user banner.jpg}">100 x 100, geen, 1</option>      <option value="{here filename if option select user banner.jpg}">80 x 80, geen, 1</option>      <option value="{here filename if option select user banner.jpg}">50 x 50, geen, 1</option>      <option value="{here filename if option select user banner.jpg}">70 x 70, geen, 1</option>  </select>  </div>  <div class="upload">  <div class="dz-filename">  <span data-dz-name="">photobanner1.jpg</span>  </div>  <input type="hidden" class="picture_upload" name="picture_upload[]">  <select class="dz-select-system" style="width: 100%;margin-top: 10px;" name="format[]">  <option selected="" disabled="" value="-1">selecteer uw formaat</option>  	<option value="{here filename if option select user photobanner1.jpg}">100 x 100, geen, 1</option>      <option value="{here filename if option select user photobanner1.jpg}">80 x 80, geen, 1</option>      <option value="{here filename if option select user photobanner1.jpg}">50 x 50, geen, 1</option>      <option value="{here filename if option select user photobanner1.jpg}">70 x 70, geen, 1</option>  </select>  </div></div>

you need set handler onchange event file input calls function to:

  • select span input
  • update span text selected file name
  • update corresponding select options selected file name

addition: can make select control sets value different input field ...

<select class="dz-select-system" style="width: 100%;margin-top: 10px;">   <option selected="" disabled="" value="-1">selecteer uw formaat</option>   <option>100 x 100, geen, 1</option>   <option>80 x 80, geen, 1</option>   <option>50 x 50, geen, 1</option>   <option>70 x 70, geen, 1</option> </select> <input id="filenamewithformat"name='filenamewithformat[]' type="hidden"> <!-- value based on input select option--> ... 

next, update javascript set value added hidden input. have used "::" delimiter here. can decide use comma or anything.

in php, you'll read value field , split delimiter file name , file format.

$(".dz-select-system").change(function() {     var $this = $(this);     var $parent = $this.parent();     var fileformat = $this.val();     var filename = $parent.find('.dz-filename span').text();      $parent.find('#filenamewithformat').val(filename + '::' + fileformat); }); 

Comments

Popular posts from this blog

neo4j - finding mutual friends in a cypher statement starting with three or more persons -

php - How to remove letter in front of the word laravel -

minify - Minimizing css files -