I have an asp.net listview with a column that contains 2 buttons, a textbox and label.
When a button is clicked a javascript function is executed.
This function takes the value in the textbox and then starts a count down in the label.
Problem is, no matter what row I select, it takes the value from first row of the listview and sets the label in the first row of the listview also.
I have made dozens of attempts to get this to work, but can’t get it to use the right row.
How can I make sure it gets and sets the correct values?
Thank you
function countdown() {
interval = setInterval(function () {
var lbl = document.getElementById("ctl00_ContentPlaceHolder1_lstViewFormulas_ctrl0_lblCountDown");
var txt = document.getElementById("ctl00_ContentPlaceHolder1_lstViewFormulas_ctrl0_txtTimeMinutes");
<asp:Button ID="buttStartTimer" runat="server" OnClientClick="javascript:countdown()" Text="Start" />
<asp:Button ID="buttStopTimer" runat="server" OnClientClick="javascript:stopcountdown()" Text="Stop" />
<asp:TextBox runat="server" ID="txtTimeMinutes" Text='<%#Eval("FormulaTiming")%>'></asp:TextBox>
<asp:Label ID="lblCountDown" runat="server" Text=""></asp:Label>
Other Attempts
<%--<input type="button" onclick='countdown()'; value="Start" id="Start" />
<input type="button" onclick='stopcountdown()'; value="Stop" id="Stop" />--%>
<%--<input type="button" onclick='countdown(this.form.TimeMinutes, this.form.spCountDown)'; value="Start" id="Start" />
<input type="button" onclick='stopcountdown()'; value="Stop" id="Stop" />--%>
<%-- <input type="button" onclick='<%# Eval("FormulaTiming", "countdown({0});")%>' value="Start" id="Button2" />
<input type="button" onclick='stopcountdown()'; value="Stop" id="Button3" />--%>
<%--<input type="text" value='<%#Eval("FormulaTiming")%>' id="txtTimeMinutes" />--%>
Could you use jquery instead:
Give all of the buttons a class and then use jquery to find that class:
Then just write your updateLabel command to update the input label
Please note, this has not been tested (just off the top of my head)