Hayes
03-19-2012, 05:44 PM
Hi Guys, Before I get started explaining my problem I would like to make it clear that this is a university web scripting assignment so I will not be asking for answers just advice as im stuck.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<style>
body{font-family: Arial,sans-serif; background-color: #86bfc9;}
#content{float:right; width: 75%;}
</style>
<script type = "text/javascript">
function showit(what,where)
{
var node = document.getElementById(where);
while( node.firstChild )
node.removeChild( node.firstChild );
node.appendChild( document.createTextNode(what) );
}
function hello()
{
alert("I'm a Computer Solutions Degree student,\n get me out of here");
}
function timestable()
{
str="you code times table here";
showit(str,"Results");
}
function formattedtimestable()
{
str="you code formatted times table here";
showit(str,"Results");
}
function alerttimestable()
{
str="you code alert times table here";
// you code here
alert(str);
}
</script>
</head>
<body>
<h1>JavaScript Exercises </h1>
<div id="content"> <div id = "Results"></div> </div>
<a href="#" OnClick = "hello()">Hello Alert</a> <br/><br/>
<a href="#" OnClick = "timestable()">Times Tables</a> <br/><br/>
<a href="#" OnClick = "alerttimestable()">Times table in an alert box</a>
<br/><br/>
<a href="#" OnClick = "formattedtimestable()">Times Tables in a Table</a>
<br/><br/>
</body>
</html>
I have been given this skeleton code and need to created the relevant times tables so a times table in a alert box, a times table in a table and a standard times table. Now the problem isn't creating the table as that's easy the problem is with the showit function. When I use the function it only prints the string once and nothing else so for example if I did
for(x = 0; x< 9; x++)
{
showit(x, "Result");
}
it will only show 8 not 1-2-3-4-5-6-7-8.
or if i did
showit("Danny", "Result");
showit("Joe", "Result");
it will only output Joe not Danny.
The content needs to go in the content div and I cant make it output more than one thing which of course is a problem as I need to output the times tables.
Sorry for the poor explanation.
Hope someone can shed some light on this
Many Thanks
Danny
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<style>
body{font-family: Arial,sans-serif; background-color: #86bfc9;}
#content{float:right; width: 75%;}
</style>
<script type = "text/javascript">
function showit(what,where)
{
var node = document.getElementById(where);
while( node.firstChild )
node.removeChild( node.firstChild );
node.appendChild( document.createTextNode(what) );
}
function hello()
{
alert("I'm a Computer Solutions Degree student,\n get me out of here");
}
function timestable()
{
str="you code times table here";
showit(str,"Results");
}
function formattedtimestable()
{
str="you code formatted times table here";
showit(str,"Results");
}
function alerttimestable()
{
str="you code alert times table here";
// you code here
alert(str);
}
</script>
</head>
<body>
<h1>JavaScript Exercises </h1>
<div id="content"> <div id = "Results"></div> </div>
<a href="#" OnClick = "hello()">Hello Alert</a> <br/><br/>
<a href="#" OnClick = "timestable()">Times Tables</a> <br/><br/>
<a href="#" OnClick = "alerttimestable()">Times table in an alert box</a>
<br/><br/>
<a href="#" OnClick = "formattedtimestable()">Times Tables in a Table</a>
<br/><br/>
</body>
</html>
I have been given this skeleton code and need to created the relevant times tables so a times table in a alert box, a times table in a table and a standard times table. Now the problem isn't creating the table as that's easy the problem is with the showit function. When I use the function it only prints the string once and nothing else so for example if I did
for(x = 0; x< 9; x++)
{
showit(x, "Result");
}
it will only show 8 not 1-2-3-4-5-6-7-8.
or if i did
showit("Danny", "Result");
showit("Joe", "Result");
it will only output Joe not Danny.
The content needs to go in the content div and I cant make it output more than one thing which of course is a problem as I need to output the times tables.
Sorry for the poor explanation.
Hope someone can shed some light on this
Many Thanks
Danny