Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript HTML VB.NET
i'm having table like this
 Response.Write("<table>")
        While intstartrecord <= intrecordcount
Response.Write("<tr>")
Response.Write("<td id="columno" onclick='showvalue()' value=" & intstartrecord & ">" & intstartrecord & "</td>")
           intstartrecord = intstartrecord + 1
           Response.Write("</tr>")
 
         End While
 Response.Write("</table>")
function showvalue()
{
alert(document.GetElementById("columnno").value)
}
 
In this When i click on any column i need to get that value. when i use this code i'm getting the same value whenever i clicked on any column ie., it is not recognizing the clicked column.

i tried getval(this) and googled but i'm not getting what i want
 
Please help me to do this
Posted 26-Jun-12 20:39pm
Agustee826
Comments
shah dipen at 27-Jun-12 6:24am
   
Hey have you got solution? if you have any difficulty reply immediately.
Agustee at 27-Jun-12 8:19am
   
i got the solution thanq.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

I implemented the small thing in C# but i guess you shuold be able to change it to VB easily. This is working as you expected it to be. Tell me if you specifically need to make it work using IDs i can do that too.
 
here is the code behind for that
 
protected void Page_Load(object sender, EventArgs e)
    {
        Response.Write("<table>");
 
        int intstartrecord = 0;
        int intrecordcount = 10;
 
        while (intstartrecord <= intrecordcount)
        {
            Response.Write("<tr>");
            Response.Write(@"<td id='columno' onclick='showvalue(this)' value=" + intstartrecord + ">" + intstartrecord + "</td>");
            intstartrecord++;
           Response.Write("</tr>");
 

        }
        Response.Write("</table>");
    }
 
and here is the javascript function i put in the aspx file
 
<script type="text/javascript">
    function showvalue(sender)
    {
        alert(sender.value);
    }
</script>
 
On a closing note: use string builder to tailor the complete string and then do response.write only once that would be better.
  Permalink  
Comments
AshishChaudha at 27-Jun-12 6:43am
   
my 5!
Rahul Rajat Singh at 27-Jun-12 6:44am
   
thanks.
Agustee at 27-Jun-12 8:03am
   
thanq so much
Rahul Rajat Singh at 27-Jun-12 8:06am
   
you are welcome. if it worked then please mark the answer as solution as this would let other know that the problems is solved and the others with similar problem can also refer and benefit from it.
Agustee at 27-Jun-12 8:18am
   
Great answer your code works i got it
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

please check the id of your td..it is same for all the columns..thats why it is returning the same value for every column.
 

Thanks
Ashish
  Permalink  
Comments
Agustee at 27-Jun-12 8:21am
   
yeah you are rite it is same for all columsn tats y i did not get it now i got it without id
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Use array of id to separate the td id:
 
Response.Write("<td id="columno[intstartrecord]" onclick='showvalue()' value=" & intstartrecord & ">" & intstartrecord & "</td>")
 
Thanks,
Elangovan
  Permalink  
Comments
Agustee at 27-Jun-12 8:22am
   
thanks for your reply
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Give unique id to each td by using counter vaiable.
  Permalink  
Comments
Agustee at 27-Jun-12 8:36am
   
thanks for the reply
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

You can create one counter, let say i, and increment it on each iteration of loop and modify your JS function like this way.
for(int i=0;i<n;i++)>
{
  Response.Write("<td  önclick='showvalue(column" & i & " )' id='column" & i & '>" & myval & "</td>");
}
 
function showvalue(id){
  alert(document.getElementById(id).innerText);
}
  Permalink  
v2
Comments
Agustee at 27-Jun-12 8:36am
   
thanq

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 George Jonsson 170
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 27 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100