简体   繁体   中英

Trying to get the text value of a field that has been updated by a dropdown selection

(JS Fiddle full code is below)

I am selecting a value from a dropdown which then based on selection will update the next table 'td' with a value. I am then looping through the table 'tr' to get a ";" separated list of all the values

In my fiddle example, I have simplified it to 2 columns where if you select "1" from the dropdown, the next field is updated with 10 and then the next row, the same

My goal is to get a list of the values in the table

For Example 1;10
            2;8

For some reason, I am looping through the table: "Get Data Button initiates loop")

$(this).find("td").filter(':visible').each(function (index) {
            if (index === 1) {
                if ($(this).find("span").val() != undefined) {
                    values += $(this).find("span").val() + ";";
                }
                if ($(this).find("text").val() != undefined) {
                    values += $(this).find("text").val() + ";";
                }
                if ($(this).find("label").text() != undefined) {
                    values += $(this).find("label").text() + ";";
                }

                if ($(this).find("select option:selected").text() != "") {
                    values += $(this).find("select option:selected").text() + ";";
                }
            }
        });

But whether I use .text(), val(), inner or outerHTML it is always ""

Thanks

http://jsfiddle.net/motti10/hjdyxv7n/4/

Don't know exactly what the purpose is, but I have the output wanted with this solution:

       if (index === 0) 
       {
            if ($(this).find("span").val()) {
                values += $(this).find("span").val() + ";";
       ....

updated the fiddle as well http://jsfiddle.net/hjdyxv7n/5/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM