I'm trying to get the value of the option of a dropdown (the selection is an ID on the markup), while opening the web Page
Using
$ (document) .ready (function () {$ ('# cat_list'). Ready (function () {var category = $ (This) .val (); Alert (category);});}); I get an empty alert.
But. (When selecting something else inside the dropdown) The following code works perfectly with the same task
$ (document) .ready (function () {$ ('# Cat_list '). Change (function () {var category = $ (this) .val (); Alert (category);});}); Finally, it works using the original javascript and it can successfully, open, refresh value, fail on the form ... etc. $ (document) .ready (function () {$ ('# cat_list') ready (function () {var e = document.getElementById ("cat_list"); var category = e.options [e.selectedIndex] .value; Alert (class);});}); Thanks for any help why the first version .ready + $ (this) .val (); Unsuccessful
The correct code is:
$ (document) .ready (Function () {var class = $ ('# cat_list'). Val (); Alert (category);});
No comments:
Post a Comment