How can I get the text inside a combobox?

Asked

Viewed 213 times

1

How can I get the 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>

http://i.stack.Imgur.com/qeEVK.png

  • 1

    You need to detail your question more.

2 answers

1

Use jQuery and send your data to the database 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);
      }
   }); 
});

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>
  • Take a look. http://jsfiddle.net/5828u2bs/

Browser other questions tagged

You are not signed in. Login or sign up in order to post.