vbscript - ASP How to get a value from HTML column -
i have asp page displays rows of data in html table, after query sql database. number of returned rows can vary. want add function when click on button, fire off query sql server database update column in particular row. use primary key result set.
the part having difficulty getting proper rows id. have wrote far returns same id every time regardless of row click on. sample code below.
<table> <tr> <td class="bold" colspan="9"><%=vheading%></td> </tr> <tr> <td class="tablehead">id</td> <td class="tablehead">whenposted</td> <td class="tablehead">whencreated</td> <td class="tablehead">whenupdated</td> <td class="tablehead">source</td> <td></td> </tr> <% while not strs.eof = + 1 %> <tr> <td id="pid<%=i%>" class="tablecell"><%=strs.fields("id")%></td> <td class="tablecell"><%=strs.fields("whenposted")%></td> <td class="tablecell"><%=strs.fields("whencreated")%></td> <td class="tablecell"><%=strs.fields("whenupdated")%></td> <td class="tablecell"><%=strs.fields("source")%></td> <td id=<%=i%>><input type="button" value="post" onclick="post();" /></td> </tr> <% strs.movenext loop %> </table> <script text="text/javascript"> function post() { var pid = document.getelementbyid("pid").innerhtml; alert(pid); } </script>
so loop through result set creating rows. examples-sake, row 1 contain id 1. row 2 have id 2 etc. if click on button fires off post method, alert shows id 1 every time, no matter row click on. guessed because assigning same id column each row. use counter variable , assign id creating unique id's columns now, i'm not sure how call function , use correct id. pointers appreciated!
you have pass i function:
<input type="button" value="post" onclick="post(<%=i%>);" />
then
<script text="text/javascript"> function post(i) { var pid = document.getelementbyid("pid"+i).innerhtml; alert(pid); } </script>
Comments
Post a Comment