Call function from another function
<p>I'm writing a calendar in Javascript, and I want to know how to get the calendar to call itself depending on which link the user clicks. At the moment the function has the name foo()</p>

<p>At the bottom, there are three different div links which are displayed depending on given circumstances. The (working) calendar was written in PHP, so I'm trying to port it into Javascript. Doing pretty well with that, but there's a few bugs that need ironing out. The problem is I just have to mimic the behavior of the PHP calendar, which sent POST values to the next or previous buttons to use as information for which month to display (etc).</p>

<p>I have tried this in two different ways with the Javascript calendar, first using a javascript void (onclick) link which called the calendar function, but apparently you can't pass variables to a function with onclick. The other way was using dom objects, but I faced a new dilemma: you can't call a function within itself.</p>

<p>So, how would I go about calling a function, by making another function and then calling the calendar from inside that one?
Thanks.</p>

<p>SystemError</p>

<p>An example:</p>

<pre><code>    function cal()
    {

    document.write("&lt;td align='left' colspan=7&gt;&lt;div id='calendar'&gt;&lt;/div&gt;&lt;/td&gt;");
    (function()
    {
            var lastday = cal[month];
                DOMcalendar = document.getElementById("calendar"),
                div = document.createElement("div");

            div.innerHTML = "&lt;a href='javascript:void(0)'&gt;Next&lt;/a&gt;";
            div.onclick = function()
            {
                cal(lastday);
            }
            DOMcalendar.appendChild(div);
    })()

    }

    cal();
</code></pre>
