How can I get the text inside a combobox?

1

How can I get text inside the combobox to add to the database?

For example, "AC" or "AL."

<select>
    <option value="1">AC</option>
    <option value="2">AL</option>
    ...
</select>

link

    
asked by anonymous 01.02.2015 / 05:15

2 answers

1

Use jQuery and send your data to the bank with Ajax:

$('select[name="combobox"]').change(function(){

   var text = $('select[name="combobox"] option:selected').text();

   $.ajax({
      url: "savar-no-bd.php",
      type: "POST",
      data: {texto: text},
      success: function(data){
         console.log(data);
      }
   }); 
});
    
01.06.2015 / 19:01
0

You can use jQuery.

jQuery

$(function(){
    $("select").change(function(){
        var that=$(this).children('option:selected');
        alert(that.text());
    });
});

HTML

<select name="combobox">
    <option value="1" class="option">Combobox Text</option>
    <option value="2" class="option">Combobox Text 2</option>
</select>
    
01.02.2015 / 07:38