• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
for each looa for document.getElementById

#1
$('.remsubmit').click(function() {
                            var indexid= "<?=$indexid?>";
                            var name = $(this).prop('id');
                            var emailid = "<?=$emailid?>";
    var remarks="";
                           
                           
                          var x = document.getElementById("mySelect").selectedIndex;
                            var y = document.getElementById("mySelect").options;
                            remarks= y[x].text;
this insert onlydata from the first dropdown

is there a way i can loop through a crud list view and get each value of selected text/value of each dropdown based on the individual id of the listed view.
Reply

#2
well, is your code vanilla js or jquery? As far as I see, you have mixed them.
Please try to go with jquery (for example) :

not var x = document.getElementById("mySelect").selectedIndex;
but var x = $('#mySelect').val();  
or  var x = $('#mySelect option: selected').val();

Not because vanilla js is wrong, but jquery will be easier for you.

+

If you want to get a value of an id, it is easy as you saw. But if you want to get values from multiple select boxes sharing the same class, please
look for Jquery each function. It will help you to solve this matter.
Reply

#3
(04-02-2021, 09:56 PM)demyr Wrote: well, is your code vanilla js or jquery? As far as I see, you have mixed them.
Please try to go with jquery (for example) :

not var x = document.getElementById("mySelect").selectedIndex;
but var x = $('#mySelect').val();  
or  var x = $('#mySelect option: selected').val();

Not because vanilla js is wrong, but jquery will be easier for you.

+

If you want to get a value of an id, it is easy as you saw. But if you want to get values from multiple select boxes sharing the same class, please
look for Jquery each function. It will help you to solve this matter.
PHP Code:
var remarks = [];
        $('#mySelect :selected').each(function() {
            remarks[$(this).val()] = $(this).text();
      
    console
.log(remarks);});


       

 
$('#mySelect').each(function(i){
   var remarks = $('#mySelect').val();

    console.log(remarks);}); 
still am not getting it any examples
Reply

#4
Could you please share your codes of this part (html-php + javascript part) ?
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.