Hi all,

I'm down with a question. How do i add in a javascript function into another function? For eg. I have a button that enable me to create a new table on the page. when the table is created, there is input of text with calendar function. Is it possible to do so?

Greatly appreciated for your help.

Recommended Answers

All 6 Replies

Depends on how you add it. If you add it as innerHTML and compose function calls with text, you could do that. If you add it with element creation, you could do it too but would be a little bit different way of adding function call to the page. It would be better to have function definition in an external javascript file and include the source at the top of the page, so you can call it whenever and wherever you want in the page.

function insCell()
{
var x=document.getElementById('tr2').insertCell(1);
var y=document.getElementById('tr1').insertCell(1);
y.innerHTML= 'Day 1';
x.innerHTML='<input type = "text" name = "day">onmouseover="if (timeoutId) clearTimeout(timeoutId);window.status='Show Calendar';return true;" onmouseout="if (timeoutDelay) calendarTimeout();window.status='';" onclick="g_Calendar.show(event,'frm.day',true,'yyyy-mm-dd'); return false;"><img src="images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt="">';
}

Here the code that i having problems with. I was thinking is there a need to append for that sentence in red and how can i append?

Arranging your code:

function insCell()
{
    var x=document.getElementById('tr2').insertCell(1);
    var y=document.getElementById('tr1').insertCell(1);
    y.innerHTML= 'Day 1';
    x.innerHTML='<input type="text" name="day" onmouseover="onOver();" onmouseout="onOut();" onclick="onClick();"><img src="images/calendar.gif" name="imgCalendar" width="34" height="21" border="0" alt="">';
}
function onOver() {
    if (timeoutId) clearTimeout(timeoutId);
    window.status='Show Calendar';
    return true;
}

function onOut() {
    if (timeoutDelay) calendarTimeout();
    window.status='';
    return true;
}

function onClick() {
    g_Calendar.show(event,'frm.day',true,'yyyy-mm-dd'); 
    return false;
}

There were typos.

Thanks!it work! but my calendar is unable to work now.

Does not work either

Hey! i solved it already! Thanks a million to you!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.