javascript - Can't access textbox for Autocomplete in repeater -
i'm trying access textbox in repeater using small javascript script. it's called ajax autocomplete when user chooses option list.
it's not working because javascript can't access textbox (id=contactid). reason because it's in repeater. how modify script access particular textbox in repeater?
<script type="text/javascript" >     function oncontactselected(source, eventargs) {     $get('<%# contactid.clientid %>').value = eventargs.get_value();     } </script> repeater code:
<asp:repeater id="itemsrepeater"        onitemdatabound="itemsrepeater_itemdatabound"        runat="server">    <itemtemplate>       <tr>          <td>           <asp:radiobuttonlist runat="server"  datasource="<%#         ((outlet)container.dataitem).outletinformations %>" datavaluefield="dateofdelivery" datatextfield="dateofdelivery" />                  </td>          <td>             <asp:textbox id="contactid" runat="server"/>          </td>       </tr>    </itemtemplate> </asp:repeater> 
it seem issue not targeting "particular" textbox. there 1 such textbox every single row of repeater, , because of nature of databinding, textboxes available @ runtime.
to fix this, need 1 of 2 things. harder, more complete answer use repeater's onitemdatabound event , pull child controls event's eventargs. option if wanted modify child control in codebehind.
however, because doing javascript , (ostensibly) want autocomplete function run on every single textbox, give table row class , target rendered input tag inside of it:
.aspx:
<itemtemplate>       <tr>          <td>           <asp:radiobuttonlist runat="server"  datasource="<%#         ((outlet)container.dataitem).outletinformations %>" datavaluefield="dateofdelivery" datatextfield="dateofdelivery" />                  </td>          <td class="autocomplete">             <asp:textbox id="contactid" runat="server"/>          </td>       </tr>    </itemtemplate> js:
<script type="text/javascript" >     function oncontactselected(source, eventargs) {       var fields = document.queryselectorall(".autocomplete input");       for(var = 0; < fields.length; i++){         fields[i].value = eventargs.get_value();       }     } </script> 
Comments
Post a Comment