title: how to get the selected item in a connected listviewer web part using javascript in sharepoint 2010
body: <p>I have a set of connected web part on a page. Basically these are out of the box webparts and are connected. The provider and consumer are connected on the user name field (donmain\userName). So selecting a value from the provider webpart updates all the consumer web parts data.</p>
  
  <p>Now my question, I would like to get the selected item from the webpart, the selected item has a "img" tag whose "alt" text is "Selected" so based on this I would like to get the selected text of the next elemet.</p>
  
  <p>This is my Mark UP and from the markup I would like the value"domain\test.officer" returned as it is the selected item.</p>
  
  <pre><code>            &lt;TABLE id={2E5002B0-EDC3-4541-A0ED-2A81797B459C}-{F1162455-D63E-481D-B13C-C1A4A59E5A34} class=ms-listviewtable border=0 cellSpacing=0 summary="Trainee " cellPadding=1 width="100%" xmlns:o="urn:schemas-microsoft-com:office:office" o:WebQuerySourceHref="http://test.app.domain.net/test/_vti_bin/owssvr.dll?CS=65001&amp;amp;XMLDATA=1&amp;amp;RowLimit=0&amp;amp;View={F1162455-D63E-481D-B13C-C1A4A59E5A34}" handleDeleteInit="true"&gt;&lt;TBODY&gt;
              &lt;TR class="ms-viewheadertr ms-vhltr" vAlign=top&gt;
              &lt;TH class=ms-vh-icon scope=col&gt;&lt;INPUT class=s4-selectAllCbx title="Select or deselect all items" onclick=ToggleAllItems(event,this,159) value="" type=checkbox&gt;&lt;/TH&gt;
              &lt;TH class=ms-vh2 onmouseover=OnChildColumn(this) scope=col noWrap&gt;
              &lt;DIV class=ms-vh-div name="SelectTitle" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;amp;SortField=SelectTitle&amp;amp;SortDir=Asc" ResultType="" FieldType="Computed" DisplayName="Select" CTXNum="159" FilterDisableMessage="" Filterable="FALSE" FilterDisable="" SortDisable="" Sortable="FALSE"&gt;Select&lt;/DIV&gt;&lt;/TH&gt;
              &lt;TH class=ms-vh-icon onmouseover=OnChildColumn(this) scope=col noWrap&gt;
              &lt;DIV class=ms-vh-div name="Attachments" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;amp;SortField=Attachments&amp;amp;SortDir=Asc" ResultType="" FieldType="Attachments" DisplayName="Attachments" CTXNum="159" FilterDisableMessage="" Filterable="" FilterDisable="" SortDisable="" Sortable=""&gt;&lt;A id=diidSortAttachments onfocus=OnFocusFilter(this) onclick="javascript:return OnClickFilter(this,event);" href="javascript: " SortingFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;amp;SortField=Attachments&amp;amp;SortDir=Asc"&gt;&lt;IMG border=0 src="/_layouts/images/attachhd.gif"&gt;&lt;IMG class=ms-hidden border=0 alt="Use SHIFT+ENTER to open the menu (new window)." src="/_layouts/images/blank.gif" width=1 height=1&gt;&lt;/A&gt;&lt;IMG border=0 alt="" src="/_layouts/images/blank.gif"&gt;&lt;IMG border=0 alt="" src="/_layouts/images/blank.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildColumn(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TH&gt;
              &lt;TH class=ms-vh2 onmouseover=OnChildColumn(this) scope=col noWrap&gt;
              &lt;DIV class=ms-vh-div name="LinkTitle" SortFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;amp;SortField=LinkTitle&amp;amp;SortDir=Asc" ResultType="" FieldType="Computed" DisplayName="Title" CTXNum="159" FilterDisableMessage="" Filterable="" FilterDisable="" SortDisable="" Sortable=""&gt;&lt;A id=diidSortLinkTitle onfocus=OnFocusFilter(this) onclick="javascript:return OnClickFilter(this,event);" href="javascript: " SortingFields="View={f1162455-d63e-481d-b13c-c1a4a59e5a34}&amp;amp;SortField=LinkTitle&amp;amp;SortDir=Asc"&gt;Title&lt;IMG class=ms-hidden border=0 alt="Use SHIFT+ENTER to open the menu (new window)." src="/_layouts/images/blank.gif" width=1 height=1&gt;&lt;/A&gt;&lt;IMG border=0 alt="" src="/_layouts/images/blank.gif"&gt;&lt;IMG border=0 alt="" src="/_layouts/images/blank.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildColumn(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TH&gt;&lt;/TR&gt;
              &lt;TR class=ms-itmhover iid="159,9,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\test.user1&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Selected align=absMiddle src="/_layouts/images/rbsel.gif"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=9 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=9&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\test.user1&lt;/A&gt;&lt;IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR class="ms-alternating ms-itmhover" iid="159,8,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\test.officer&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','8');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','8');return false;" target=_self&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"&gt;&lt;/A&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=8 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=8&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\test.officer&lt;/A&gt;&lt;IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR class=ms-itmhover iid="159,5,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\n.test&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','5');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','5');return false;" target=_self&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"&gt;&lt;/A&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=5 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=5&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\n.test&lt;/A&gt;&lt;IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR class="ms-alternating ms-itmhover" iid="159,3,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\test1.user1&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','3');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','3');return false;" target=_self&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"&gt;&lt;/A&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=3 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=3&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\test1.user1&lt;/A&gt;&lt;IMG class=ms-newgif title=New alt=New src="/_layouts/1033/images/new.gif"&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR class=ms-itmhover iid="159,2,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\admin.user&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','2');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','2');return false;" target=_self&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"&gt;&lt;/A&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=2 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=2&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\admin.user&lt;/A&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;
              &lt;TR class="ms-alternating ms-itmhover" iid="159,1,0" setEdgeBorder="true"&gt;
              &lt;TD class="ms-vb-itmcbx ms-vb-firstCell"&gt;&lt;INPUT class=s4-itm-cbx title="domain\portal.user&amp;#13;&amp;#10;  " value="" type=checkbox _setup="true"&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;A onclick="SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','1');return false;" href="javascript:SelectField('{F1162455-D63E-481D-B13C-C1A4A59E5A34}','1');return false;" target=_self&gt;&lt;IMG style="CURSOR: hand" border=0 alt=Normal align=absMiddle src="/_layouts/images/rbunsel.gif"&gt;&lt;/A&gt;&lt;/TD&gt;
              &lt;TD class=ms-vb2&gt;&lt;/TD&gt;
              &lt;TD class="ms-vb-title ms-vb-lastCell" onmouseover=OnChildItem(this) height="100%"&gt;
              &lt;DIV id=1 class="ms-vb itx" onmouseover=OnItem(this) EventType="" Perm="0x7fffffffffffffff" Field="LinkTitle" CTXName="ctx159"&gt;&lt;A onfocus=OnLink(this) onclick="EditLink2(this,159);return false;" href="http://test.app.domain.net/test/_layouts/listform.aspx?PageType=4&amp;amp;ListId={2E5002B0-EDC3-4541-A0ED-2A81797B459C}&amp;amp;ID=1&amp;amp;ContentTypeID=0x0100801F054C4E00C243A9A49EC13FF778D7003293EF8DE37E144BAA8A5296D5E6CA8B" target=_self&gt;domain\portal.user&lt;/A&gt;&lt;/DIV&gt;
              &lt;DIV class=s4-ctx onmouseover="OnChildItem(this.parentNode); return false;"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A onfocus="OnChildItem(this.parentNode.parentNode); return false;" title="Open Menu" onclick="PopMenuFromChevron(event); return false;" href="javascript:;"&gt;&lt;/A&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/DIV&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
  </code></pre>