javascript - Get values by class -
i tried hours not find solution.
simplified code looks following.
php :
foreach($db->query("select id news order position asc") $row) { ... <input type="text" class="_title" > search: <input type="file" class="_file" > <input type='button' class="_submit" value='save' > ... } ?>
js :
$(document).ready(function(){ $("._submit").click(function(){ ?? var _title = document.getelementbyid('_title'), ?? _file = document.getelementbyid('_file'); var data = new formdata(); data.append('selectedfile', _file.files[0]); data.append('title', _title.value); ... </script>
i don't know how data class. id working, can't use ids, because there several same ids because of foreach loop.
tried without success:
var _file = document.getelementsbyclassname('_file');
i hope can me. misch
you can wrap elements in container div like
<?php foreach($db->query("select id news order position asc") $row) { ... <div class='container'> <input type="text" class="_title" > search: <input type="file" class="_file" > <input type='button' class="_submit" value='save' > </div> } ?>
then use .closest()
traverse container. after wards use find
desired elements.
<script> $(document).ready(function(){ $("._submit").click(function(){ var container = $(this).closest('.container'); var _title = container.find('._title'), var _file = container.find('._file')[0]; var data = new formdata(); data.append('selectedfile', _file.files[0]); data.append('title', _title.value); //rest of code }); }); </script>
Comments
Post a Comment