/    Sign up×
Community /Pin to ProfileBookmark

Javascript – Code Debugging – please help

Hey people of webdeveloper, i am a new at coding, only been programming javascript for 7 weeks, lol

learning at my education campus. So i need some help with this program i am writting, its no way near done, and it is just a simple script using basic knowledge. Atm its just in its very begining

Basically i am trying to make a table creator, lol, somthing simple until i get better, and please go easy on me =]], if you need anymore info, just ask.

Heres the code:

[CODE]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Table Creator v1.0</title>
<script type=”text/javascript” language=”javascript”>

function createtable() {

var rownumber;
var counter;

// counter is declared
counter = 1
rownumber = parseInt(document.creatorform.rows.value);
document.write(“<table>”);
while (counter<rownumber) {
// getting element aka the div tag called divv, lol and changing the info in it
document.getElementById(“divv”).innerHTML='<tr><td>Hello</td></tr>’;
counter++
}
document.write(“</table>”);
}
</script>
<link href=”table_creator.css” rel=”stylesheet” type=”text/css” />
</head>

<body>
<div id=”dynamictableform” align=”center”>
<form name=”creatorform”>
<table width=”350″>
<tr><th colspan=”2″>Table Creator v1.0</th></tr>
<tr><th>Number Of Rows:</th><td><input type=”text” name=”rows” /></td></tr>
<tr><th>Number Of Colums:</th><td><input type=”text” name=”colums” /></td></tr>
<tr><th>Border Size:</th><td><input type=”text” name=”border” /></td></tr>
<tr><th>Table Width:</th><td><input type=”text” name=”width” /></td></tr>
<tr><th>Table Hieght:</th><td><input type=”text” name=”hieght” /></td></tr>
<tr><th>Colour Of Cells:</th><td><input type=”text” name=”cellsc” /></td></tr>
<tr><th>Colour Of Text:</th><td><input type=”text” name=”textc” /></td></tr>
<tr><th>Font Type:</th><td><input type=”text” name=”fontt” /></td></tr>
<tr><th>Font Size:</th><td><input type=”text” name=”fonts” /></td></tr>
<tr><td colspan=”2″ align=”center”><input type=”submit” name=”create” onclick=”createtable()” value=”Create Table” />
<input type=”reset” onclick=”createtable()” value=”Reset” /></td></tr>
</table>
</form>
</div>
<div id=”divv” align=”center”>
<br />
No table has been created at this point of time.
<br />
</div>
</body>
</html>
[/CODE]

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@TheBearMaySep 02.2008 — Some minor changes to get you moving:

[code=html]<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Table Creator v1.0</title>
<script type="text/javascript">

function createtable() {
var rownumber;
var counter;
// counter is declared
counter = 1
rownumber = parseInt(document.creatorform.rows.value);
var newTab = "<table>";
while (counter<rownumber) {
newTab+='<tr><td>Hello</td></tr>';
counter++
}
newTab+="</table>";
// getting element aka the div tag called divv, lol and changing the info in it
document.getElementById("divv").innerHTML=newTab;

}
</script>
<link href="table_creator.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="dynamictableform" align="center">
<form name="creatorform" action="#" onsubmit="createtable();return false;">
<table width="350">
<tr><th colspan="2">Table Creator v1.0</th></tr>
<tr><th>Number Of Rows:</th><td><input type="text" name="rows" /></td></tr>
<tr><th>Number Of Colums:</th><td><input type="text" name="colums" /></td></tr>
<tr><th>Border Size:</th><td><input type="text" name="border" /></td></tr>
<tr><th>Table Width:</th><td><input type="text" name="width" /></td></tr>
<tr><th>Table Hieght:</th><td><input type="text" name="hieght" /></td></tr>
<tr><th>Colour Of Cells:</th><td><input type="text" name="cellsc" /></td></tr>
<tr><th>Colour Of Text:</th><td><input type="text" name="textc" /></td></tr>
<tr><th>Font Type:</th><td><input type="text" name="fontt" /></td></tr>
<tr><th>Font Size:</th><td><input type="text" name="fonts" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="create" value="Create Table" />
<input type="reset" value="Reset" /></td></tr>
</table>
</form>
</div>
<div id="divv" align="center">
<br />
No table has been created at this point of time.
<br />
</div>
</body>
</html>[/code]
Copy linkTweet thisAlerts:
@zargisauthorSep 03.2008 — thanks heaps
Copy linkTweet thisAlerts:
@zargisauthorSep 03.2008 — Umm i might need some more help, lol when i run this code below and you put in the row input box the number 1, and you put the rest of the fields in and all that, it comes up with a blank cell LOL :S but the border works and width and hieght, also i need help making abit of code to make it allow you to add colums

:S

please help =]

thanks people

also i am having abit of trouble understanding the new stuff, could you help by commenting the new bits, thanks, i really appreciate you time and help =]

[CODE]
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Table Creator v1.0</title>
<script type="text/javascript" language="javascript">

function createtable() {
var rownumber;
var counter;
var border;
var width;
var height;
var cellsc;
var textc;
var fontt;
var fonts;
// counter is declared
counter = 1
rownumber = parseInt(document.creatorform.rows.value);
border = parseInt(document.creatorform.border.value);
width = parseInt(document.creatorform.width.value);
height = parseInt(document.creatorform.height.value);
cellsc = document.creatorform.cellsc.value;
textc = document.creatorform.textc.value;
fontt = document.creatorform.fontt.value;
fonts = parseInt(document.creatorform.fonts.value);
var newTab = "<table border='" + border + "' width='" + width + "' height='" + height + "'>";
while (counter<rownumber) {
newTab+='<tr><td bgcolor="' + cellsc + '"><font color="' + textc + '" face="' + fontt + '" size="' + fonts + '">Hello</font></td></tr>';
counter++
}
newTab+="</table>";
// getting element aka the div tag called divv, lol and changing the info in it
document.getElementById("divv").innerHTML=newTab;

}
</script>
<link href="table_creator.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="dynamictableform" align="center">
<form name="creatorform" action="#" onsubmit="createtable();return false;">
<table width="350">
<tr><th colspan="2">Table Creator v1.0</th></tr>
<tr><th>Number Of Rows:</th><td><input type="text" name="rows" /></td></tr>
<tr><th>Number Of Colums:</th><td><input type="text" name="colums" /></td></tr>
<tr><th>Border Size:</th><td><input type="text" name="border" /></td></tr>
<tr><th>Table Width:</th><td><input type="text" name="width" /></td></tr>
<tr><th>Table Hieght:</th><td><input type="text" name="height" /></td></tr>
<tr><th>Colour Of Cells:</th><td><input type="text" name="cellsc" /></td></tr>
<tr><th>Colour Of Text:</th><td><input type="text" name="textc" /></td></tr>
<tr><th>Font Type:</th><td><input type="text" name="fontt" /></td></tr>
<tr><th>Font Size:</th><td><input type="text" name="fonts" /></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="create" value="Create Table" />
<input type="reset" value="Reset" /></td></tr>
</table>
</form>
</div>
<div id="divv" align="center">
<br />
No table has been created at this point of time.
<br />
</div>
</body>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@FangSep 03.2008 — This is depreciated; use DOM stylenewTab+='&lt;tr&gt;&lt;td bgcolor="' + cellsc + '"&gt;&lt;font color="' + textc + '" face="' + fontt + '" size="' + fonts + '"&gt;Hello&lt;/font&gt;&lt;/td&gt;&lt;/tr&gt;';
Copy linkTweet thisAlerts:
@zargisauthorSep 03.2008 — what has depreciated :S that peice of code ??

please post the fixed code, :S and tell me what actally function is depreciated please =]
Copy linkTweet thisAlerts:
@FangSep 03.2008 — The use of [I]bgcolor[/I] and [I]font[/I]
newTab+='&lt;tr&gt;&lt;td style="background-color:' + cellsc + ';color:' + textc + ';font-family:' + fontt + ';font-size:' + fonts + '"&gt;Hello&lt;/td&gt;&lt;/tr&gt;';
×

Success!

Help @zargis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...