Jump to content

Calling Javascript function from dynamically created table


YongJ
 Share

Recommended Posts

Is it possible to have my table that loads an xml document and creates a table dynamically to store that information and create additional tags to receive information from a javascript function? Here is the code. At this moment, the only way for it to print is if the tags are manually created in the .htm file.

table+=("</td></tr>");var yr = 2018;var m = 5;var d = 10;var hr = 12;var min = 12;table+=("<tr>");table+=("<td onload="countdown(yr,m,d,hr,min)"> Time Left : </td>");

table+=("<td><div id="dday"></div></td>");table+=("<td><div id="dhour"></div></td>");table+=("<td><div id="dmin"></div></td>");table+=("<td><div id="dsec"></div></td>");table+=("</tr>");table+=("<tr><td>");

the function it calls is called countdown and it displays the result using inner.html

document.getElementById('dday').innerHTML=dday;document.getElementById('dhour').innerHTML=dhour;document.getElementById('dmin').innerHTML=dmin;document.getElementById('dsec').innerHTML=dsec;

Please help Thank you

Will this work?

Link to comment
Share on other sites

table+=("<tr>");
table+=("<script type="text/javascript" src="countdown.js"></script>");
table+=("<td> Time Left : </td>");
table+=("<td><div id="dday"></div></td>");
table+=("<td><div id="dhour"></div></td>");
table+=("<td><div id="dmin"></div></td>");
table+=("<td><div id="dsec"></div></td>");
table+=("</tr>");
table+=("<script">);
table+=("countdown(yr,m,d,hr,min)");
table+=("</script">);
I have made some changes. It doesn't seem to work. Can you suggest a solution?
Link to comment
Share on other sites

table+=("<tr>");
table+=("<script type="text/javascript" src="countdown.js"></script>");
table+=("<td> Time Left : </td>");
table+=("<td><div id="dday"></div></td>");
table+=("<td><div id="dhour"></div></td>");
table+=("<td><div id="dmin"></div></td>");
table+=("<td><div id="dsec"></div></td>");
table+=("</tr>");
table+=("<script type="text/javascript">");
table+=("countdown(yr,m,d,hr,min)");
table+=("</script>");
table+=("<tr><td>");
This is my test. It loads however, there is no output anywhere. May I know how I can solve this
Link to comment
Share on other sites

Oh thanks.

May I know how i can solve this second issue. my second function which is located in the external javascript file isn't returning any information to the first function that was called from the script tag.

 

table+=("<td><div id="dday"></div></td>");
table+=("<td><div id="dhour"></div></td>");
table+=("<td><div id="dmin"></div></td>");
table+=("<td><div id="dsec"></div></td>");
table+=("</tr>");
table+=("<script type="text/javascript">");
table+=("countdown(yr,m,d,hr,min)");
table+=("</script>");
table+=("<tr><td>");
ignore the brackets for now.
document.getElementById('dday').innerHTML="AA";
document.getElementById('dhour').innerHTML=dhour;
document.getElementById('dmin').innerHTML=dmin;
document.getElementById('dsec').innerHTML=dsec;
setTimeout("countdown(theyear,themonth,theday,thehour,theminute)",1000);
Link to comment
Share on other sites

Which function isn't returning anything? I was just suggesting to build the table first, output it, then run the function. e.g.:

/* build table here */document.getElementById('table').innerHTML = table;countdown(yr,m,d,hr,min);
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...