1
<table id="GridView1">
 <tr>
    <th>KeyWord</th>
    <th>Identifiers</th>
    <th>Values</th>
 </tr>
 <tr>
    <td>
        <select >
           <option selected="selected" value="Action A">Action A</option>
           <option  value="Action b">Action b</option>
           <option value="Action C">Action C</option>
        </select>
    </td>
    <td>
        <textarea >adsasd</textarea>
    </td>
        <td>
        <textarea >dsad</textarea>
    </td>
 </tr>
  <tr>
    <td>
        <select >
           <option value="Action A">Action A</option>
           <option selected="selected" value="Action b">Action b</option>
           <option value="Action C">Action C</option>
        </select>
    </td>
    <td>
        <textarea >asdasd</textarea>
    </td>
        <td>
        <textarea >sdsad</textarea>
    </td>
 </tr>
 </table>

This is the js.

var xml = '<?xml version="1.0" encoding="utf-8"?>';
xml = xml + '<Root>';
i=0;
$("#GridView1 tr").each(function () {

 $(this).find('td').each (function() {
    alert($(this).find('select').val())

  alert($(this).find('textarea').val())


});

});

xml = xml + '</Root>'
alert(xml)

I am getting all the values inside the td but also getting undefined. Any idea why ?

2
  • Your fiddle is different than code you posted Commented Feb 4, 2016 at 13:17
  • why you want dropdown and texarea values like this ? cant you use id or by name ? Commented Feb 4, 2016 at 13:19

3 Answers 3

2

You get undefined because it tries to display the select value AND the textarea value for EACH td.

To show only the existing values, just check if the element exists within the td:

if($(this).find('textarea').length > 0) {
  alert($(this).find('textarea').val());
}
Sign up to request clarification or add additional context in comments.

1 Comment

how to make it show the value only if there is a select or textarea and not otherwise
1

Demo

$("table").find("td").each(function(){
alert($(this).html());


})

1 Comment

wow I answered your question and you changed the whole question . why did you put a wrong jsfiddle demo than ???
0

Find all select and textarea in tr instead of td like following.

$("#GridView1 tr").find('select, textarea').each(function () {
    alert(this.value);
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.