Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap Dropdown get value of selected item

With the Bootstrap dropdown-toggle buttons is there any way to show the value that has just been selected?

<form action="/output/" name="InputCacheCheck" method="post">
{% csrf_token %}
    <div class="input-prepend input-append">
        <div class="btn-group">

            <button class="btn dropdown-toggle" name="recordinput" data-toggle="dropdown">
            Record
            <span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                  <li><a href="#">A</a></li>
                  <li><a href="#">CNAME</a></li>
                  <li><a href="#">MX</a></li>
                  <li><a href="#">PTR</a></li>
            </ul>
        <input class=".input-large" name="hostnameinput" id="appendedInputButton" type="text">
        <button class="btn" type="submit">Lookup</button>
        </div>
    </div>
</form>

Also the name recordinput isn't being supplied within the forms POST data. Any ideas?

like image 953
felix001 Avatar asked Jun 15 '13 20:06

felix001


People also ask

How do I get selected value from a bootstrap select drop down?

You can get the selected value's text with $(this). find("option:selected"). text() .

How to get the selected value in dropdown using React?

To fetch the selected value from the select element, you can use the onChange event handler prop. Just like the input or textarea elements, you can use the onChange event handler to get the value from the event object. Now, make this select input element controlled by using the state to pass the value.


1 Answers

You should be able to change the dropdown text like this..

$(".dropdown-menu li a").click(function(){
  var selText = $(this).text();
  $(this).parents('.btn-group').find('.dropdown-toggle').html(selText+' <span class="caret"></span>');
});

Demo http://www.bootply.com/64302

How is the form being 'POST'ed?

like image 177
Zim Avatar answered Sep 28 '22 09:09

Zim