Click here to Skip to main content
15,886,664 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear All,
I want to pass three textbox values to a javascript function. However its not working.Any help is really appreciated.

What I have tried:

<asp:ImageButton ID="ibut_cheque2" runat="server" target="_blank" OnClientClick='<%# string.Format("window.open(\"Product.aspx?pid=\" + document.getElementById(\"{0}\").value & chdate=\" + document.getElementById(\"{1}\").value & pname=\" + document.getElementById(\"{2}\").value, null,\"scrollbars=yes,top=10,left=10\", \"true\");", Form.FindControl("txt_voucher").ClientID,Form.FindControl("txtbox_chqdate").ClientID,Form.FindControl("txtbox_chprovider").ClientID)%>'
                                    AlternateText="Print" CssClass="btn5" ForeColor="White" ToolTip="Print Cheque" />
Posted
Updated 15-Nov-17 16:30pm

1 solution

Simplify it by placing the code in a function
<script>
        function openWindow() {
            var pid = document.getElementById('<%=txt_voucher.ClientID %>');
            var chdate = document.getElementById('<%=txtbox_chqdate.ClientID %>');
            var pname = document.getElementById('<%=txtbox_chprovider.ClientID %>');
            window.open("Product.aspx?pid=" + pid + "chdate= " + chdate + " & pname= " + pname + ", null,scrollbars=yes,top=10,left=10", "true");
        }
    </script>


<asp:ImageButton ID="ibut_cheque2" runat="server" target="_blank" OnClientClick='openWindow()' AlternateText="Print" CssClass="btn5" ForeColor="White" ToolTip="Print Cheque" />
 
Share this answer
 
Comments
Member 12926744 15-Nov-17 22:42pm    
While doing it I am getting an error "The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>)."Can you please help me
Karthik_Mahalingam 15-Nov-17 22:45pm    
place the script before the end of body tag
reference [^]
Member 12926744 15-Nov-17 22:56pm    
Product.aspx?cid=[object%20HTMLInputElement]chdate=%20[object%20HTMLInputElement]%20&%20pname=%20[object%20HTMLInputElement],%20null,scrollbars=yes,top=10,left=10

The values is passed like this .ie I think the variables are not getting textbox values.
Karthik_Mahalingam 15-Nov-17 23:02pm    
Oh My mistake, forget to add the value property
should be
function openWindow() {
            var pid = document.getElementById('<%=txt_voucher.ClientID %>').value;
            var chdate = document.getElementById('<%=txtbox_chqdate.ClientID %>').value;
            var pname = document.getElementById('<%=txtbox_chprovider.ClientID %>').value;
Member 12926744 15-Nov-17 23:41pm    
Thank you very much .It worked.Its opening in new tab.But I need to open it in new window.Can you please help me.I am new to javascript.

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900