Asked  7 Months ago    Answers:  5   Viewed   22 times

How can I get the selected value of a dropdown box using jQuery?
I tried using

var value = $('#dropDownId').val();

and

var value = $('select#dropDownId option:selected').val();

but both return an empty string.

 Answers

17

For single select dom elements, to get the currently selected value:

$('#dropDownId').val();

To get the currently selected text:

$('#dropDownId :selected').text();
Tuesday, June 1, 2021
 
Sidarta
answered 7 Months ago
70

That can be achieved real easily by listening events. You could make the color red for example by adding class and removing class to autocomplete. I think you can accomplish this yourself with a little bit of effort.

select: function( event, ui ) {
    var terms = split( this.value );
    if(terms.length <= 2) { 
        // remove the current input
        terms.pop();
        // add the selected item
        terms.push( ui.item.value );
        // add placeholder to get the comma-and-space at the end
        terms.push( "" );
        this.value = terms.join( ", " );
        return false;
    } else {
        var last = terms.pop();
        $(this).val(this.value.substr(0, this.value.length - last.length - 2)); // removes text from input
        $(this).effect("highlight", {}, 1000);
        $(this).addClass("red");
        $("#warnings").html("<span style='color:red;'>Max people reached</span>");
        return false;
    }
}

P.S I also think one of these plugins could be suitable thanks to google:


  1. https://github.com/loopj/jQuery-Tokenizing-Autocomplete-Plugin

    Looks nice in my opinion:

    Demo tokenizing Autocomplete Plugin

    Click link to view live demo.

  2. http://net.tutsplus.com/tutorials/javascript-ajax/how-to-use-the-jquery-ui-autocomplete-widget/

  3. Facebook style JQuery autocomplete plugin
Wednesday, March 31, 2021
 
Camsoft
answered 9 Months ago
86

Try this:

private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
    ComboBox cmb = (ComboBox)sender;
    int selectedIndex = cmb.SelectedIndex;
    int selectedValue = (int)cmb.SelectedValue;

    ComboboxItem selectedCar = (ComboboxItem)cmb.SelectedItem;
    MessageBox.Show(String.Format("Index: [{0}] CarName={1}; Value={2}", selectedIndex, selectedCar.Text, selecteVal));        
}
Thursday, June 10, 2021
 
Baba
answered 6 Months ago
86

Step 1: Take a NSString variable in your appDelegate.

Step 2: create instance of appDelegate in your both view were your want to set value and get value as following.

yourApplicationDelegate *appDelegate;

Step 3: init appDelgate in implementation file as following

appDelegate = [[UIApplication sharedApplication] delegate];

after this statement you can use the string variable from both view controller you declared in appDelegate of you application.

That's it. now you can assign value from first view and access it in second view.

Saturday, July 31, 2021
 
rblarsen
answered 4 Months ago
44

Use the position option to align the top of the dialog with the top of the window (plus a pixel or percent offset).

This should center the dialog horizontally and position it 150 pixels from the top.

$("#dialog-form").dialog({
    autoOpen: false,
    width: 630,
    position: { my: 'top', at: 'top+150' },
    modal: true,
    resizable: false,
    closeOnEscape: false
});

Older versions of jQuery UI used an array containing an [x,y] coordinate pair in pixel offset from left, top corner of viewport (e.g. [350,100]).

var dialogWidth = 630;
$("#dialog-form").dialog({
    // ...
    width: dialogWidth,
    position: [($(window).width() / 2) - (dialogWidth / 2), 150],
    // ...
});
Sunday, August 8, 2021
 
jdmcbr
answered 4 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :  
Share