document.getElementById('button2').click(); not working
<p>I am try to automatically fire a sub routine with with a javascript "document.getElementById('button2').click();" as it is in the below code. Can someone please help me see why the  code is not working. Thank you</p>

<pre><code>&lt;%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" debug = "true"%&gt;
&lt;%@ Import Namespace="System.Data.SqlClient"%&gt;
&lt;%@ Import Namespace="System.Data"%&gt;
&lt;script language="vb" runat="server"&gt;
Sub sendmsg(sender As Object, e As EventArgs)
response.Redirect("index.aspx")
End Sub
&lt;/script&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;script&gt;
function Confirm() {
    var str = $('#loutput').val(); //'We are inviting you for s special business meeting on Tueday, at No 12, Fred street. for more information please call 02341123333';

    var updateString = function(input_text) {
        //1. Find consecutive 11 numeric digits
        var match = input_text.match(/\d{11}/);
        //2. divide it into a string of 3s separated by space
        var new_str = '';
        for (var i = 1; i &lt; match[0].length + 1; i++) {
            new_str = new_str + match[0][i - 1];
            if (i &gt; 1 &amp;&amp; i % 3 == 0)
                new_str = new_str + ' ';
        }
        //3. Replace old match no. with the new one
        console.log(match)
        if (match[0] != '')
            var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Message contains numeric characters which might make the message not delivered to some networks. Do you want us to reformat the message ?. This might increase the numbers of pages of the message and the cost?")) {
            confirm_value.value = "Yes";
            input_text = input_text.replace(match[0], new_str)
            $('#loutput').val(input_text);
            confirm2()

            //document.getElementById('loutput').innerHTML = input_text;

        } else {
            confirm_value.value = "No";
            confirm2()
        }
        $('#loutput').val(input_text);
        //document.getElementById('loutput').innerHTML = input_text;
    };
    updateString(str);
};

function confirm2() {
    var confirm_value = document.createElement("INPUT");
    confirm_value.type = "hidden";
    confirm_value.name = "confirm_value";
    if (confirm(" send the message now?")) {
        confirm_value.value = "Yes";
        document.getElementById('button2').click();

        //document.getElementById('loutput').innerHTML = input_text;

    } else {
        confirm_value.value = "No";
    }

    //document.getElementById('loutput').innerHTML = input_text;
};
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;   &lt;/script&gt;
&lt;form runat="server" action="formatmessage3.aspx" method="post"&gt;
&lt;input type="texarea" id="loutput" name="loutput" value="&lt;%=request.form ("loutput") %&gt;" /&gt;
&lt;button ID="button1" OnClick="Confirm();" runat="server"&gt;Confirm&lt;/button&gt;
&lt;asp:button ID="button2" OnClick="sendmsg" Text="send" runat="server" /&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>