Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 18, 2012 01:25 PM by Damn Code
Member
138 Points
139 Posts
Aug 18, 2012 07:38 AM|LINK
hi everybody,
I am using literal control
lituser.Text = sb.ToString();
in that i bind usernames when we click on usernames i want to call javascript function ie.
onclick="javascript:chatWith('username')"
so how to call that javasctipt function
Please send the code
Thanks in advance.
Contributor
2868 Points
436 Posts
Aug 18, 2012 08:51 AM|LINK
Hi Friend,
Literal control don' t have any ID in HTML when rendered. You can place all your literal controls in a table and use jQuery to find the value of the literal controls.
Below code might achieve your needs:
HTML Code
<table id="litUser"> <tr> <td> <asp:Literal Text="John" runat="server" /> </td> <td> <asp:Literal Text="Bond" runat="server" /> </td> </tr> </table>
Javascript Code
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> $(document).ready(function () { $('#litUser td').click(function () { var UserName = $(this).html(); chatWith(UserName); }); }); function chatWith(userName) { alert('Chat With: ' + userName); } </script>
Reply me in case of any issues or help needed.
Participant
1883 Points
323 Posts
Aug 18, 2012 01:25 PM|LINK
Hi, friend
Have a look at this. hope helps you
http://stackoverflow.com/questions/4820163/calling-a-function-in-javascript-object-literal-notation-declaration
keerthijagin...
Member
138 Points
139 Posts
how to call javascript function to literal
Aug 18, 2012 07:38 AM|LINK
hi everybody,
I am using literal control
lituser.Text = sb.ToString();
in that i bind usernames when we click on usernames i want to call javascript function ie.
onclick="javascript:chatWith('username')"
so how to call that javasctipt function
Please send the code
Thanks in advance.
shashank_meh...
Contributor
2868 Points
436 Posts
Re: how to call javascript function to literal
Aug 18, 2012 08:51 AM|LINK
Hi Friend,
Literal control don' t have any ID in HTML when rendered. You can place all your literal controls in a table and use jQuery to find the value of the literal controls.
Below code might achieve your needs:
HTML Code
<table id="litUser"> <tr> <td> <asp:Literal Text="John" runat="server" /> </td> <td> <asp:Literal Text="Bond" runat="server" /> </td> </tr> </table>Javascript Code
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> <script type="text/javascript" language="javascript"> $(document).ready(function () { $('#litUser td').click(function () { var UserName = $(this).html(); chatWith(UserName); }); }); function chatWith(userName) { alert('Chat With: ' + userName); } </script>Reply me in case of any issues or help needed.
Damn Code
Participant
1883 Points
323 Posts
Re: how to call javascript function to literal
Aug 18, 2012 01:25 PM|LINK
Hi, friend
Have a look at this. hope helps you
http://stackoverflow.com/questions/4820163/calling-a-function-in-javascript-object-literal-notation-declaration
Please remember to Mark the replies as Answers if they help & unmark them if they provide no help.