Using DropDownListFor jquery does not get the currently selected value

gilesrpa

I have added an onchange event to the DropDownlistFor which is working fine, I think.

I am adding a new dropdownlistfor into the DOM so that I can have multiple selected items (note the multiple dropdowns contain different data sources).

When the dropdowns are created, the id's are all different, but work along the lines of

newObject_XX__dropDownName

Where XX is an incremental number starting at 0, and are added to the DOM using the following:

$(XX).change(function(){ FunkyTest(this); });

Where XX is newObject_XX__dropDownName from above.

And the javascript function FunckyTest is as follows.

function FunkyTest(event)
{
    var e = event.id;
    var elem = "select#" + e + " option.selected"
    var t = $(elem).text();
    var v = $(elem).val();
    alert(q); 
}

I am trying to get the currently selected data from the dropdown.

$("select#newObject_XX__dropDownName option:selected").text();

This is the method shown by the jQuery website, but when I replace the "select#newObject_XX__dropDownName option:selected" for the var elem within FunkyTest it does not work.

gilesrpa

Don't worry all.

Found solution.....

var t = $("select#" + event.id + " option:selected").text()
var v = $("select#" + event.id + " option:selected").val()

Does the job.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get currently selected value of UIPickerView

From Dev

Unable to get @Html.DropDownListFor Selected Value

From Dev

Using selected value in @Html.DropDownListFor

From Dev

dropdownlistfor selected value with viewdata

From Dev

DropDownListFor selected value not working

From Dev

get hidden value of the currently selected radio button

From Dev

get hidden value of the currently selected radio button

From Dev

Get selected value of <select> using jQuery

From Dev

Get Dropdown selected value using JQuery

From Dev

Get value of selected option using jquery

From Dev

Get value of selected option using jquery

From Dev

Kendo MVC DropDownListFor does not bind selected value to model

From Dev

Set selected value for DropDownListFor in controller does not work in razor view

From Dev

Get DropDownListFor selected value into Ajax.ActionLink call

From Dev

DropDownListFor<> not using my selected value if I change it in the model before call

From Dev

DropDownListFor<> not using my selected value if I change it in the model before call

From Dev

DropDownListFor not always showing selected value

From Dev

'dropdownlistfor' controller not taking the selected value

From Dev

MVC DropDownListFor selected value not being selected

From Dev

Trying to know which element is currently selected on a @Html.DropDownListFor

From Dev

How to get the value of the currently selected Selectize.js input item

From Dev

How to I get the currently selected check value from CheckedListBox?

From Java

Get selected value of a dropdown's item using jQuery

From Dev

Trying to get value of selected radio button using ajax/jquery

From Dev

How to get the last value selected from dropdown and disable it using jquery

From Dev

Get key value for selected option in select using jquery

From Dev

Get selected value of a dropdown using jQuery into a javascript function

From Dev

How to get value of all selected checkbox by using jQuery?

From Dev

Get value of selected image in Jquery

Related Related

  1. 1

    Get currently selected value of UIPickerView

  2. 2

    Unable to get @Html.DropDownListFor Selected Value

  3. 3

    Using selected value in @Html.DropDownListFor

  4. 4

    dropdownlistfor selected value with viewdata

  5. 5

    DropDownListFor selected value not working

  6. 6

    get hidden value of the currently selected radio button

  7. 7

    get hidden value of the currently selected radio button

  8. 8

    Get selected value of <select> using jQuery

  9. 9

    Get Dropdown selected value using JQuery

  10. 10

    Get value of selected option using jquery

  11. 11

    Get value of selected option using jquery

  12. 12

    Kendo MVC DropDownListFor does not bind selected value to model

  13. 13

    Set selected value for DropDownListFor in controller does not work in razor view

  14. 14

    Get DropDownListFor selected value into Ajax.ActionLink call

  15. 15

    DropDownListFor<> not using my selected value if I change it in the model before call

  16. 16

    DropDownListFor<> not using my selected value if I change it in the model before call

  17. 17

    DropDownListFor not always showing selected value

  18. 18

    'dropdownlistfor' controller not taking the selected value

  19. 19

    MVC DropDownListFor selected value not being selected

  20. 20

    Trying to know which element is currently selected on a @Html.DropDownListFor

  21. 21

    How to get the value of the currently selected Selectize.js input item

  22. 22

    How to I get the currently selected check value from CheckedListBox?

  23. 23

    Get selected value of a dropdown's item using jQuery

  24. 24

    Trying to get value of selected radio button using ajax/jquery

  25. 25

    How to get the last value selected from dropdown and disable it using jquery

  26. 26

    Get key value for selected option in select using jquery

  27. 27

    Get selected value of a dropdown using jQuery into a javascript function

  28. 28

    How to get value of all selected checkbox by using jQuery?

  29. 29

    Get value of selected image in Jquery

HotTag

Archive