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
Text Box to Appear When a Radio Button Is Selected
Different Color for Each Bar in a Bar Chart; Chartjs
Puppeteer Wait Until Page Is Completely Loaded
How to Redirect to Another Page in Reactjs When a If Condition Is Executed
Css Div Height Not Expanding to Fit Content or Wrapping Content
Get Array of Values from Multiple Inputs Using Jquery
Get Image from Json File Using JavaScript and Display in HTML Img Tag
How to Wait Until All JavaScript Files Are Loaded Before Executing JavaScript Code
How to Replace All Words of Length Less Than 3 in a String With " " (Space) in JavaScript
How to Validate Mobile Number for Countries in Angular
How to Monitor Changes to an Object
How to Download a File With Node.Js (Without Using Third-Party Libraries)
React .Map() Is Not a Function Error
Jquery Datatables: Hide Search Bar
Change Value of a Variable Inside Foreach Loop? Make It Available Outside the Loop
How to Push Array in Array in Angular