|
| |
|
|
fatlardo
Posts: 76 Joined: 4/15/2004 From: Shrewsbury Status: offline
|
'Undefined' error in JavaScript - 7/5/2004 6:15:01
I am using the script below to try and create a page that will create a graph based on a users input. Im getting the following error: Line: 135 Error: 'xlinepos0' is undefined The code I am using is:
<html>
<head>
<script language="JavaScript">
function numcompare(a,b) {
return a-b;
}
function drawgraph() {
var noofbars = document.graph.noofbars.value;
var barwidth = 300 / noofbars;
var bar1value = document.graph.bar1value.value;
var bar1name = document.graph.bar1name.value;
var bar2value = document.graph.bar2value.value;
var bar2name = document.graph.bar2name.value;
var bar3value = document.graph.bar3value.value;
var bar3name = document.graph.bar3name.value;
var bar4value = document.graph.bar4value.value;
var bar4name = document.graph.bar4name.value;
var bar5value = document.graph.bar5value.value;
var bar5name = document.graph.bar5name.value;
values = new Array(5);
values[1] = bar1value;
values[2] = bar2value;
values[3] = bar3value;
values[4] = bar4value;
values[5] = bar5value;
sortedvalues = values.sort(numcompare);
var topvalue = values[5];
var bar1heightper = (bar1value / topvalue) * 100;
var bar1heightpix = (bar1heightper / 100) * 300;
var bar2heightper = (bar2value / topvalue) * 100;
var bar2heightpix = (bar2heightper / 100) * 300;
var bar3heightper = (bar3value / topvalue) * 100;
var bar3heightpix = (bar3heightper / 100) * 300;
var bar4heightper = (bar4value / topvalue) * 100;
var bar4heightpix = (bar4heightper / 100) * 300;
var bar5heightper = (bar5value / topvalue) * 100;
var bar5heightpix = (bar5heightper / 100) * 300;
var axisvalue0 = 0;
var axisvalue1 = topvalue / 4;
var axisvalue2 = topvalue / 2;
var axisvalue3 = (topvalue / 4) * 3;
var axisvalue4 = topvalue;
var xwordpos1 = (300 / noofbars) * 0 + 5;
var xwordpos2 = (300 / noofbars) * 1 + 5;
var xwordpos3 = (300 / noofbars) * 2 + 5;
var xwordpos4 = (300 / noofbars) * 3 + 5;
var xwordpos5 = (300 / noofbars) * 4 + 5;
var xlinepos0 = 0;
var xlinepos1 = ((300 / noofbars) * 1) + 20;
var xlinepos2 = ((300 / noofbars) * 2) + 20;
var xlinepos3 = ((300 / noofbars) * 3) + 20;
var xlinepos4 = ((300 / noofbars) * 4) + 20;
var xlinepos5 = ((300 / noofbars) * 5) + 20;
xlines()
}
</script>
</head>
<body>
<h2>Bar Charts</h2>
In order to use this bar chart, you need to specify a few values:
<form name=graph onsubmit="drawgraph()">
Number of bars:<input type=text name=noofbars>
<p />
<table>
<tr>
<td> </td>
<td><b>Bar Name:</b></td>
<td><b>Bar Value:</b></td>
</tr>
<tr>
<td>1</td>
<td><input type=text name=bar1name></td>
<td><input type=text name=bar1value></td>
</tr>
<tr>
<td>2</td>
<td><input type=text name=bar2name></td>
<td><input type=text name=bar2value></td>
</tr>
<tr>
<td>3</td>
<td><input type=text name=bar3name></td>
<td><input type=text name=bar3value></td>
</tr>
<tr>
<td>4</td>
<td><input type=text name=bar4name></td>
<td><input type=text name=bar4value></td>
</tr>
<tr>
<td>5</td>
<td><input type=text name=bar5name></td>
<td><input type=text name=bar5value></td>
</tr>
</table>
<input type=submit value="draw graph">
</form>
<!-- Axis Lines -->
<img src="line.bmp" width=301px height=1px style="position:absolute;left:20px;top:650px">
<img src="line.bmp" width=1px height=301px style="position:absolute;left:20px;top:350px">
<img src="line.bmp" width=5px height=1px style="position:absolute;left:15px;top:650px">
<img src="line.bmp" width=5px height=1px style="position:absolute;left:15px;top:575px">
<img src="line.bmp" width=5px height=1px style="position:absolute;left:15px;top:500px">
<img src="line.bmp" width=5px height=1px style="position:absolute;left:15px;top:425px">
<img src="line.bmp" width=5px height=1px style="position:absolute;left:15px;top:350px">
<!-- Labelling the axis -->
<!-- X-axis lines -->
<script language="JavaScript">
function xlines() {
document.write("<div style='position:absolute;left:" + xlinepos0 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
document.write("<div style='position:absolute;left:" + xlinepos1 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
document.write("<div style='position:absolute;left:" + xlinepos2 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
document.write("<div style='position:absolute;left:" + xlinepos3 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
document.write("<div style='position:absolute;left:" + xlinepos4 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
document.write("<div style='position:absolute;left:" + xlinepos5 + ";top:651'><img src='line.bmp' width=1 height=5></div>")
}
</script>
<img src="line.bmp" width=102% height=1px style="position:absolute;left:0px;top:700px">
</body>
</html>
It still isn't finished, but that shouldn't affect the xlinepos0 variable. Can anyone see where I've gone wrong? HELP!!!
|
|
|
|
Giomanach
Posts: 6128 Joined: 11/19/2003 From: England Status: offline
|
RE: 'Undefined' error in JavaScript - 7/5/2004 8:32:04
You need a semi-colon at the end of: xlines() Dan
_____________________________
|
|
|
|
fatlardo
Posts: 76 Joined: 4/15/2004 From: Shrewsbury Status: offline
|
RE: 'Undefined' error in JavaScript - 7/5/2004 8:58:38
I'm getting a page can't be found displayed error now. It should be able to find the page because the submit button links back to the same page that it's on. I've tried adding an action attribute to the form tag but it hasn't worked. Any ideas?
|
|
New Messages |
No New Messages |
Hot Topic w/ New Messages |
Hot Topic w/o New Messages |
Locked w/ New Messages |
Locked w/o New Messages |
|
Post New Thread
Reply to Message
Post New Poll
Submit Vote
Delete My Own Post
Delete My Own Thread
Rate Posts
|
|
|