PDA

View Full Version : Javascript and DHTML



susie123
11-29-2007, 09:47 AM
Hi. I have a script that worked last week and this week doesnīt want to!!! Can anybody please have a look and tell me where the error is, if any, or if itīs my pc? Many thanks for your help.

<script language=JavaScript>

function flags()
{
var filter = "Team = "+team.value;

teamLogo.src = "images\\"+team.value+".jpg";

teamlist.Filter = filter;
teamlist.reset();
}

function backwardClick()
{
if (teamlist.recordset.AbsolutePosition > 1)
{
teamlist.recordset.MovePrevious();
flags();
}
else
{
alert("Beginning of team list.");
}
}

function forwardClick()
{
if (teamlist.recordset.AbsolutePosition != teamlist.recordset.RecordCount)
{
teamlist.recordset.MoveNext();
flags();
}
else
{
alert("End of team list.");
}
}
</script>
</head>

<body onload="flags()" bgcolor="#99ffcc">

<font face="verdana,arial,helvetica" color="#3300ff">
<center>
<h2>WORLD SWIMMING CHAMPIONSHIPS 2007</h2>

<h3>Individual Swimmer Statistics</h3>

<hr width="650pt" color="#3333ff">

<p>Click the buttons below to see who won races for your country this year.</p>
<p>

<object id="teamlist" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="indivSwimStats.txt">
<param name="UseHeader" value="True">
</object>

<img id="teamLogo" src="images\Great Britain.jpg" border=2 height=60 width=77 align=center alt="Team's Flag">
<br>
<table>
<tr>
<td align=right> <input type=button id=backward value=" < " onclick="backwardClick()">
</td>
<td align=left> <input type=button id=forward value=" > " onclick="forwardClick()"></td>
</tr>
</table>

<table width="85%" bgcolor="#ccffcc" border="1" align=center cellspacing=1 cellpadding=5 id="results" datasrc="#teamlist">

<THEAD>
<TR>
<TD><DIV ID="team"><B>Team</B></DIV></TD>
<TD width="5%"><DIV ID="Total"><center><B>Total races won</B></center></DIV></TD>
<TD width="20.5%"><DIV ID="Name2"><B>Freestyle</B></DIV></TD>
<TD><DIV ID="Name3"><B>Backstroke</B></DIV></TD>
<TD><DIV ID="Name4"><B>Butterfly</B></DIV></TD>
<TD width="18%"><DIV ID="Name5"><B>Relay</B></DIV></TD>
</TR>
</THEAD>
<TBODY>
<TR>
<TD><DIV DATAFLD="team"></DIV></TD>
<TD align="center"><DIV DATAFLD="Total"></DIV></TD>
<TD><DIV DATAFLD="Name2"></DIV></TD>
<TD><DIV DATAFLD="Name3"></DIV></TD>
<TD><DIV DATAFLD="Name4"></DIV></TD>
<TD><DIV DATAFLD="Name5"></DIV></TD>
</TR>
</TBODY>
</table>

Look forward to hearing from you. Thanks again.

:)

boogyman
11-29-2007, 02:00 PM
if any, or if itīs my pc?
its not your computer

I believe we have told you before, but when you are posting code please use the
tags.... Its very difficult for us to read computer code in regular post formatting.



<script language=JavaScript>

the language script attribute was decpreciated in favor of type
[code]
<script type="text/javascript">




<script type="text/javascript">
function flags()
{
var filter = "Team = "+team.value;

teamLogo.src = "images\\"+team.value+".jpg";

teamlist.Filter = filter;
teamlist.reset();
}

function backwardClick()
{
if (teamlist.recordset.AbsolutePosition > 1)
{
teamlist.recordset.MovePrevious();
flags();
}
else
{
alert("Beginning of team list.");
}
}

function forwardClick()
{
if (teamlist.recordset.AbsolutePosition != teamlist.recordset.RecordCount)
{
teamlist.recordset.MoveNext();
flags();
}
else
{
alert("End of team list.");
}
}</script>
</head>

thank you for putting the javascript code in the head tag. alot of people do not know that is where it should be. none of your definitions should ever evaluate to anything because you are referencing them incorrectly. The fact that IE saw them last week and not this week is a good example of this. It hypothesized before of what you were attempting to do, however this week it did what it should have done and left them alone.


document.form.element.value

is the proper way to reference and element in a file.
its good that you declared the variable filter and setting it to a value, just follow the method above and it should work.


var filter = "Team = " + document.swim.team.value;

now every other variable in your flags() function is not declared before being defined. what I mean by that is you are not passing it into the function and you are just assigning it on the whim. Now that is acceptable in javascript language, but it is bad coding technique so just declare them as variables and you will be able to use them as you like (following the method above)



<form name="swim">


<object id="teamlist" classid="clsid:333C7BC4-460F-11D0-BC04-0080C7055A83">
<param name="DataURL" value="indivSwimStats.txt">
<param name="UseHeader" value="True">
</object>

<img id="teamLogo" src="images\Great Britain.jpg" border=2 height=60 width=77 align=center alt="Team's Flag">
<br>
<table>
<tr>
<td align=right> <input type=button id=backward value=" < " onclick="backwardClick()">
</td>
<td align=left> <input type=button id=forward value=" > " onclick="forwardClick()"></td>
</tr>
</table>

<table width="85%" bgcolor="#ccffcc" border="1" align=center cellspacing=1 cellpadding=5 id="results" datasrc="#teamlist">

<THEAD>
<TR>
<TD><DIV ID="team"><B>Team</B></DIV></TD>
<TD width="5%"><DIV ID="Total"><center><B>Total races won</B></center></DIV></TD>
<TD width="20.5%"><DIV ID="Name2"><B>Freestyle</B></DIV></TD>
<TD><DIV ID="Name3"><B>Backstroke</B></DIV></TD>
<TD><DIV ID="Name4"><B>Butterfly</B></DIV></TD>
<TD width="18%"><DIV ID="Name5"><B>Relay</B></DIV></TD>
</TR>
</THEAD>
<TBODY>
<TR>
<TD><DIV DATAFLD="team"></DIV></TD>
<TD align="center"><DIV DATAFLD="Total"></DIV></TD>
<TD><DIV DATAFLD="Name2"></DIV></TD>
<TD><DIV DATAFLD="Name3"></DIV></TD>
<TD><DIV DATAFLD="Name4"></DIV></TD>
<TD><DIV DATAFLD="Name5"></DIV></TD>
</TR>
</TBODY>
</table>

</form>


while you should be using CSS to style your table and the contents, I just added the <form> at the top and bottom to tell the browser to prepare for some user input. just make sure that the document.swim and the <form name="swim"> are the same or you will still be encountering the same problem