Get Selected Item Value from Bootstrap Dropdown With Specific Id

Get selected item value from Bootstrap DropDown with specific ID

$('#demolist li').on('click', function(){
$('#datebox').val($(this).text());
});

http://jsfiddle.net/kcpma/18/

selected item value from Bootstrap DropDown with specific ID

You have to use attr() instead of data() :

var inputValue = $(this).attr('value');

data("value") is used to get data-value="test" attribute.

And as pointed by @u_mulder, you have to change selectvalue to inputValue, or change into your { value: inputValue } to { value: selectvalue }.

Get selected text from bootstrap dropdown

You need to attach the click() handler to the a element within the ul that gets toggled. You can then retrieve the text() of that element and set it to the related button. Try this:

$("#tableMenu a").on('click', function(e) {  e.preventDefault(); // cancel the link behaviour  var selText = $(this).text();  $("#tableButton").text(selText);});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><div id="tableDiv" class="dropdown">  <button id="tableButton" class="btn btn-primary dropdown-toggle" type="button" data-toggle="dropdown">        Table        <span class="caret"></span>    </button>  <ul id="tableMenu" class="dropdown-menu">    <li><a href="#">Att1</a></li>    <li><a href="#">Att2</a></li>    <li><a href="#">Att3</a></li>  </ul></div>

How to get an value from a bootstrap dropdown menu (jQuery)

Its not value its data.

https://api.jquery.com/data/

$(element).data('value');

html bootstrap dropdown get index of selected item

If you're sending the request outside of click handler scope, you can set a variable with a null value and update it on .click()

var selected_index = null;
$('.dropdown-menu a').on('click', function(){
$(this).parent().parent().prev().html($(this).html() + '<span class="caret"></span>');
selected_index = $(this).closest('li').index();
});

// ... HTTP request code with selected_index

Twitter Bootstrap: How do I get the selected value of dropdown?

Bootstrap provides you with minimum required functionality for your implementation, they aren't dropdowns instead they are mere ul, li's with css applied on it and some events registered in the bootstrap plugin for toggling the button to display them as dropdown. This one you need to do on your own.

Set up some identifier to the status button say a className btnStatus and bind a click event to the dropdown links. and do something like this?

$('.dropdown-inverse li > a').click(function(e){
$('.btnStatus').text(this.innerHTML);
});

Demo

Access boostrap dropdown value in JS when multiple dropdowns rendered



Related Topics



Leave a reply



Submit