Get the value of a select between multiple select in html5

1

I have a question, to see if they can give me a hand. I have a table with several items, each one has 1 select with 2 payment options, cash and card, what I need is that when the option is changed, I show the value of that combo that changed with JQuery.

Here's what I did in html5:

 <td>
 <select name="FormaDePago" id="">
 <option value="Tarjeta">Tarjeta</option>
 <option value="Efectivo">Efectivo</option>
 </select>
 </td>

And here what I have been doing with Jquery:

$(document).ready(function () { 

   $(".FormaDePago").change(function(){

      let formaPago = $(this).val();
      alert(formaPago);
      });
});
    
asked by GALS 30.09.2018 в 22:06
source

1 answer

1

Well, you have the code completely fine, but what you're having is a concept error.

In your Jquery you are trying to associate a change event with an element that has the class PaymentShape :

JQUERY

 $(".FormaDePago").change(function(){

What is happening? That in your HTML you do not have any elements with the PaymentShape class but you have an element with the name PaymentShape .

The simplest thing would be to include in your HTML the class you're referencing from your Jquery tag, leaving it like this:

HTML

<td>
    <select name="FormaDePago" id="" class="FormaDePago">
        <option value="Tarjeta">Tarjeta</option>
        <option value="Efectivo">Efectivo</option>
    </select>
</td>
    
answered by 01.10.2018 / 09:15
source