0

Hi am Trying to count the character inside the Repeater Control of Text Box It is working fine if I will Placed the Text Box outside the Repeater Control.Please do something as needful.Here I attach the Code of Html and Java Script.how can count the character of text box inside Repeater.Kindly help me out.Here i will Take TextBox Id txtarea and count the character in Label id is lblcharcnt.

  <asp:TextBox ID="txtarea" runat="server" Width="700px" Height="80px" TextMode="MultiLine" onkeyup="cnt()" MaxLength="1000"></asp:TextBox>
  <p style="text-align: right;">
    <asp:Label ID="lblcharcnt" runat="server" Text="1000"></asp:Label>

  </p>
  <asp:Label ID="lblcount" runat="server" Text='<%#Eval("row") %>' Visible="false"></asp:Label>


  </ItemTemplate>
</asp:Repeater>

<script type="text/javascript">
  function cnt() {
    var a = document.getElementById("txtarea").value;
    document.getElementById("lblcharcnt").innerHTML = 15 - a.length;
  }
</script>
cweiske
  • 30,033
  • 14
  • 133
  • 194
  • `lblcharcnt` is your server id. Your client id will be different. My suggestion, add a common class to textarea. Now use this class to attach event using `.addEventListener` and use `this` to navigate to necessary element – Rajesh Feb 28 '17 at 10:26
  • how can add addEventListener – Mani Kumar Feb 28 '17 at 10:37
  • http://stackoverflow.com/questions/19655189/javascript-click-event-listener-on-class – Rajesh Feb 28 '17 at 10:37
  • it working fine out side the Repeater.but it is not working inside the Repeater. – Mani Kumar Feb 28 '17 at 10:40
  • hi sir please help – Mani Kumar Feb 28 '17 at 11:04
  • Apologies but i'm not very familiar with ASP, but you can use either [this](https://msdn.microsoft.com/en-us/library/windows/apps/dn301909.aspx) as reference or try to fetch elements by class. – Rajesh Feb 28 '17 at 11:08
  • Idea is, **Step1:** Fetch elements by class. **Step2:** Add listeners to them. **Step3:** Using `this`(*current element*), navigate to element and set its value (`this.nextSibling.querySelector('p').textContent = 15-this.value.length`) – Rajesh Feb 28 '17 at 11:10
  • All OP-provided information pertinent to the question should be added to the question via edit, not via comment. Please add your commented code block to your question and delete the comment. – mickmackusa Feb 28 '17 at 11:25

0 Answers0