Results 1 to 2 of 2

Thread: Javascript and DHTML

  1. #1
    Join Date
    Aug 2007
    Location
    Barcelona
    Posts
    28
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default Javascript and DHTML

    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.


  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    Quote Originally Posted by susie123 View Post
    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 [code] 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.
    Code:
    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.
    Code:
    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)

    Code:
    <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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •