locked
Javascript function RRS feed

  • Question

  • User-2062901272 posted

    Hi Experts,

    I just wanna confirm if i use the control item as parameters example:

    my idea is i want to reuse the said JavaScript function.

    Sample:

    function myfunction(ControldID)
    {
     var x = document.geelementid('<%=ControldID.clientID%>').value;
    
    alert(x);
    }

    <asp:TextBox ID="txtReEmail" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lnkbtnPassport" runat="server" OnClientClick="myfunction(document.getElementById('<%=txtEmail.ClientID%>'))">View email</asp:LinkButton>

    Thanks and Best regards.

    Wednesday, April 11, 2018 3:27 AM

Answers

  • User516094431 posted

    If you want to remain in the aspx page, you have to put a name of a javascript function in the OnClientClick and implement the javascript function in a script tag:

    <asp:TextBox ID="txtReEmail" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lnkbtnPassport" runat="server" OnClientClick="myfunction(this)">View email</asp:LinkButton>
    
    
    <script>
        function myfunction(ControldID) {
            // ControldID: object of LinkButton if any need to use this
            var x = document.getElementById('<%=txtReEmail.ClientID%>').value;
            alert(x);
        }
    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 11, 2018 6:11 AM

All replies

  • User516094431 posted

    If you want to remain in the aspx page, you have to put a name of a javascript function in the OnClientClick and implement the javascript function in a script tag:

    <asp:TextBox ID="txtReEmail" runat="server"></asp:TextBox>
    <asp:LinkButton ID="lnkbtnPassport" runat="server" OnClientClick="myfunction(this)">View email</asp:LinkButton>
    
    
    <script>
        function myfunction(ControldID) {
            // ControldID: object of LinkButton if any need to use this
            var x = document.getElementById('<%=txtReEmail.ClientID%>').value;
            alert(x);
        }
    </script>

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, April 11, 2018 6:11 AM
  • User-2062901272 posted

    Hi mshoaiblibra,

    I get your point. Thanks.

    Wednesday, April 11, 2018 7:25 AM
  • User1799400417 posted

    Great idea, 

    Just simple and clear cool

    Thursday, April 12, 2018 12:44 PM