Вопрос по javascript, jquery, html – JQuery Получить выбранный вариант из выпадающего

987

Error: User Rate Limit Exceeded$("#id").val()Error: User Rate Limit ExceededaioConceptName

html code

<label>Name</label>
<input type="text" name="name" />
<select id="aioConceptName">
    <option>choose io</option>
    <option>roma</option>
    <option>totti</option>
</select>
Error: User Rate Limit ExceededvalueError: User Rate Limit Exceeded<option>Error: User Rate Limit Exceeded Jacob Valenta
Error: User Rate Limit Exceeded$("#aioConceptName").val()Error: User Rate Limit Exceededchoose io. Salman A
Error: User Rate Limit ExceededjQuery: Get selected option from dropdown Kenny Linsky
Error: User Rate Limit Exceededjsfiddle.net/pAtVPError: User Rate Limit Exceeded Jorge
Error: User Rate Limit Exceeded#aioConceptName Jorge

Ваш Ответ

26   ответов
6

Error: User Rate Limit Exceeded

var conceptName = $('#aioConceptName').val();
3

console.log($('#aioConceptName option:selected').val())
9

Error: User Rate Limit ExceededjQuery.val()Error: User Rate Limit Exceeded

The .val() method is primarily used to get the values of form elements such as input, select and textarea. In the case of select elements, it returns null when no option is selected and an array containing the value of each selected option when there is at least one and it is possible to select more because the multiple attribute is present.

$(function() {
  $("#aioConceptName").on("change", function() {
    $("#debug").text($("#aioConceptName").val());
  }).trigger("change");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<select id="aioConceptName">
  <option>choose io</option>
  <option>roma</option>
  <option>totti</option>
</select>
<div id="debug"></div>

0

var bOK = true;
$('.optKategorien').each(function(index,el){
    if($(el).find(":selected").text() == "") {
        bOK = false;
    }
});
2

Error: User Rate Limit Exceeded

$(document).ready(function() {

    $("#name option").filter(function() {
        return $(this).val() == $("#firstname").val();
    }).attr('selected', true);

    $("#name").live("change", function() {

        $("#firstname").val($(this).find("option:selected").attr("value"));
    });
});


<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<select id="name" name="name"> 
<option value="">Please select...</option> 
<option value="Elvis">Elvis</option> 
<option value="Frank">Frank</option> 
<option value="Jim">Jim</option> 
</select>

<input type="text" id="firstname" name="firstname" value="Elvis" readonly="readonly">
303

Set the values for each of the options

    <option value="0">choose io</option>
    <option value="1">roma</option>
    <option value="2">totti</option>
</select>

$('#aioConceptName').val()Error: User Rate Limit Exceeded.val()Error: User Rate Limit ExceededvalueError: User Rate Limit ExceededvalueError: User Rate Limit Exceeded<option>.

Error: User Rate Limit Exceeded$('#aioConceptName').val()Error: User Rate Limit Exceeded:selectedError: User Rate Limit Exceeded

Error: User Rate Limit ExceededpromptError: User Rate Limit Exceeded<option>Please select an option</option>Error: User Rate Limit Exceeded<option value="">Please...</option>Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded.val()Error: User Rate Limit Exceeded$(":selected).text()Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededval()Error: User Rate Limit ExceededvalueError: User Rate Limit ExceededoptionError: User Rate Limit Exceeded1Error: User Rate Limit Exceededroma.
Error: User Rate Limit Exceeded$('#aioConceptName').val()Error: User Rate Limit Exceeded
17
$('#aioConceptName option:selected').val();
0

Error: User Rate Limit Exceeded$("#drpList").val();

Error: User Rate Limit Exceeded
149

var conceptName = ,$('#aioConceptName :selected').text();

$('#id :pseudoclass')

Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededmeta.stackexchange.com/questions/87678/…Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded.find(':selected')Error: User Rate Limit Exceeded$('#aioConceptname').bind('change', function(el) { console.log ( $(el).find(':selected').text() ); });
Error: User Rate Limit ExceededquerySelectorAll()Error: User Rate Limit ExceededjQuery docsError: User Rate Limit ExceededEliot's solution.
Error: User Rate Limit Exceeded
2

Error: User Rate Limit Exceeded

Your dropdown

<select id="aioConceptName">
    <option>choose io</option>
    <option>roma</option>
    <option>totti</option>
</select>

Jquery code to get the selected value

$('#aioConceptName').change(function() {
    var $option = $(this).find('option:selected');

    //Added with the EDIT
    var value = $option.val(); //returns the value of the selected option.
    var text = $option.text(); //returns the text of the selected option.
});
-1

$('#aioConceptName').change(function(){

   //get the selected val using jQuery's 'this' method and assign to a var
   var selectedVal = $(this).val();

   //perform the rest of your operations using aforementioned var

});

2

Error: User Rate Limit Exceeded

var conceptName = $('#aioConceptName').find(":selected").attr('value');
Error: User Rate Limit Exceeded
1649

var conceptName = $('#aioConceptName').find(":selected").text();

val():selectedchild

Error: User Rate Limit Exceeded.val()Error: User Rate Limit Exceeded
Error: User Rate Limit Exceeded
Error: User Rate Limit Exceededvar mySelect = $('#mySelect'); /* ... more code happens ... */ var selectedText = mySelect.find(':selected').text();
Error: User Rate Limit Exceededvar conceptVal = $("#aioConceptName option:selected").val()?
Error: User Rate Limit Exceededval()Error: User Rate Limit Exceededvar conceptVal = $("#aioConceptName option").filter(":selected").val();?
0

Error: User Rate Limit Exceeded

<select onchange="your_action(this.value)">
   <option value='*'>All</option>
   <option ... />
</select>
0

<label>Name</label>
<input type="text" name="name" />
<select id="aioConceptName">
    <option value="choose">choose io</option>
</select>

   $("#aioConceptName").find(':selected').text();

9

change

$("#aioConceptName").change(function () {
    alert($("#aioConceptName :selected").text())
});

$("#aioConceptName").change(function () {
    alert($("#aioConceptName :selected").attr('value'))
});
9

var value = $('#Id :selected').val();

var values = $('#aioConceptName :selected').val();

2

Error: User Rate Limit Exceeded$('select[id="aioConceptName[]"] option:selected').each(function(key,value){ options2[$(this).val()] = $(this).text(); console.log(JSON.stringify(options2)); });
Error: User Rate Limit ExceededError: User Rate Limit Exceeded

29

var box = document.getElementById('aioConceptName');

conceptName = box.options[box.selectedIndex].text;

44


$(this).find('option:selected')

$('dropdown_selector').change(function() {
    //Use $option (with the "$") to see that the variable is a jQuery object
    var $option = $(this).find('option:selected');
    //Added with the EDIT
    var value = $option.val();//to get content of "value" attrib
    var text = $option.text();//to get <option>Text</option> content
});

Edit

option.val().

Error: User Rate Limit Exceeded$(this).find('option:selected').val()Error: User Rate Limit Exceeded$(this).find('option:selected').text()Error: User Rate Limit Exceeded
11

Reading the value (not the text) of a select:

var status = $("#Status")[0].value;
var status = $('#Status option:selected').val();

How to disable a select? in both variants, value can be changed using:

A

Error: User Rate Limit Exceeded

$('#Status').prop('disabled', true);

B

Error: User Rate Limit Exceeded

$('#Status option').attr('disabled', true);

Error: User Rate Limit Exceeded$("#Status").val() will only workError: User Rate Limit Exceeded1.9.0Error: User Rate Limit Exceeded

How to update a disabled select?

Error: User Rate Limit Exceeded

$("#Status").val(2);

Error: User Rate Limit Exceeded

$("#Status").val(2).change();
11
<select id="form-s" multiple="multiple">
    <option selected>city1</option>
    <option selected value="c2">city2</option>
    <option value="c3">city3</option>
</select>   
<select id="aioConceptName">
    <option value="s1" selected >choose io</option>
    <option value="s2">roma </option>
    <option value="s3">totti</option>
</select>
<select id="test">
    <option value="s4">paloma</option>
    <option value="s5" selected >foo</option>
    <option value="s6">bar</option>
</select>
<script>
$('select').change(function() {
    var a=$(':selected').text(); // "city1city2choose iofoo"
    var b=$(':selected').val();  // "city1" - selects just first query !
    //but..
    var c=$(':selected').map(function(){ // ["city1","city2","choose io","foo"]
        return $(this).text();
    }); 
    var d=$(':selected').map(function(){ // ["city1","c2","s1","s5"]
        return $(this).val();
    });
    console.log(a,b,c,d);
});
</script>
Error: User Rate Limit Exceeded:selectedError: User Rate Limit Exceededmap()Error: User Rate Limit Exceeded
0

Error: User Rate Limit Exceeded

$("select#aioConceptName > option:selected").text()

Error: User Rate Limit Exceeded

$("select#aioConceptName > option:selected").val()
50

$("select#id_of_select_element option").filter(":selected").val();

$("select#id_of_select_element option").filter(":selected").text();
8

Error: User Rate Limit Exceeded

Error: User Rate Limit Exceeded

  $( "#aioConceptName option:selected" ).attr("value");

Error: User Rate Limit Exceeded

0


selectval()

Похожие вопросы