Reputation: 3515
How do I pass parameters in window.open method.
<table id="tblUsers" cellspacing="0" >
<asp:Repeater ID="repUsers" runat="server">
<ItemTemplate>
<tr><td> <a ID="hlUser" runat="server" Target="_new" onclick="return OpenWindow();" ><%# Eval("Username") %></a></td></tr>
</ItemTemplate>
</asp:Repeater>
</table>
function OpenWindow() {
var toUsername = document.getElementById("hlUser");
window.open("ChatWindow.aspx?username=" + toUsername.value, "ChatWindow", "width=350,height=250");
return null;
}
Upvotes: 0
Views: 7629
Reputation: 27880
I don't know much about asp.net, but looks like you have a javascript problem. Isn't document.getElementById("hlUser")
an <a>
element? It has no value
attribute.
If you want to get the text element inside the <a>
you could query the text
property, or innerHTML
.
<a id="hlUser">somevalue</a>
document.getElementById('hlUser').text
will return somevalue
UPDATE:
Having that <a>
inside a repeater makes it impossible to know with confidence any id
attribute inside it beforehand. I'd reccomend passing the <a>
element, or this.text
itself , or even the value using the same server-side script to the function.
UPDATE 2: I see this question might be a duplicate of How do I pass a variable using window.open()?
Upvotes: 1
Reputation: 415705
Just change the & to a +:
function OpenWindow() {
var toUsername = document.getElementById("hlUser");
window.open("ChatWindow.aspx?username=" + toUsername.value, "ChatWindow", "width=350,height=250");
return null;
}
At this level of code, you're working in Javascript rather than VB, and VB's use of & for concatenation is an oddity among programming languages.
Upvotes: 0