javascript stopwatch

Any idea why my stopwatch produces the error Microsoft JScript runtime error: Object expected when i click start as i dont se ewhy its not working

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="stats.aspx.vb" Inherits="stats" %>

<!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 runat="server">
    <title></title>
    <link href="Styles/Site.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="javascript/stopwatch.js"></script>   
    <style type="text/css">
        #starttime
        {
            width: 111px;
            height: 22px;
        }
        #theendtime
        {
            width: 106px;
        }
    </style>
</head>
<body> 
    <form id="form1" runat="server">
   
        <div id="Wrapper">
            <div id="SignIn">
                <div id="username"><asp:Label ID="user" runat="server" Text="Label"></asp:Label></div>  
             
                <div id="pagetitle">Logged Time Off The Phones</div>
            </div>

            <div id="cont">
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                <asp:ListItem Value="Key Rec"></asp:ListItem>
                <asp:ListItem Value="Computer Land"></asp:ListItem>
                <asp:ListItem Value="Other"></asp:ListItem>
                </asp:DropDownList>	
                <asp:TextBox ID="TextBox1" runat="server" Visible="False" Width="154px"></asp:TextBox>
                <input type="text" id="txt" value="00:00:00:0"/><asp:Button ID="start" runat="server" Text="Start" /><asp:Button ID="reset" runat="server" Text="Stop" Visible="False" />
                <br />
                <br />
                <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
                    CellPadding="3" DataSourceID="SqlDataSource1" AllowPaging="True" 
                    EnableTheming="False" BackColor="White" BorderColor="#CCCCCC" 
                    BorderStyle="None" BorderWidth="1px">
                    <Columns>
                        <asp:BoundField DataField="thedate" DataFormatString="{0:MM/dd/yyyy}" 
                            HeaderText="Date" SortExpression="thedate">
                        <ItemStyle Font-Size="Smaller" />
                        </asp:BoundField>
                        <asp:BoundField DataField="starttime" DataFormatString="{0:hh:mm:ss tt}" 
                            HeaderText="Start Time" SortExpression="starttime" >
                        <ItemStyle Font-Size="Smaller" />
                        </asp:BoundField>
                        <asp:BoundField DataField="endtime" DataFormatString="{0:hh:mm:ss tt}" 
                            HeaderText="End Tme" SortExpression="endtime" >
                        <ItemStyle Font-Size="Smaller" />
                        </asp:BoundField>
                        <asp:BoundField DataField="totaltime" HeaderText="Total Time" 
                            SortExpression="totaltime" >
                        <ItemStyle Font-Size="Smaller" />
                        </asp:BoundField>
                        <asp:BoundField DataField="reason" HeaderText="Reason" 
                            SortExpression="reason" >
                        <ControlStyle Font-Size="Smaller" />
                        <ItemStyle Font-Size="Smaller" />
                        </asp:BoundField>
                    </Columns>
                    <EmptyDataTemplate>
                        <table>
                            <tr>
                                <td>
                                    <a Href="javascript:__doPostBack('GridView1','Page$1')" style="color:White;">1</a></td>
                                <td>
                                    <span>2</span></td>
                            </tr>
                        </table>
                    </EmptyDataTemplate>
                    <FooterStyle BackColor="White" ForeColor="#000066" />
                    <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
                    <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
                    <RowStyle ForeColor="#000066" />
                    <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
                    <SortedAscendingCellStyle BackColor="#F1F1F1" />
                    <SortedAscendingHeaderStyle BackColor="#007DBB" />
                    <SortedDescendingCellStyle BackColor="#CAC9C9" />
                    <SortedDescendingHeaderStyle BackColor="#00547E" />
                </asp:GridView>
                <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                    ConnectionString="Data Source=TS-NOT-IIS02VS;Initial Catalog=SupportDev;Persist Security Info=True;User ID=supportdev-web;Password=B9vafUG4Ca3a" 
                    ProviderName="System.Data.SqlClient" 
                    SelectCommand="SELECT [thedate], [starttime], [endtime], [totaltime], [reason] FROM [phonestats] ORDER BY [thedate]">
                </asp:SqlDataSource>
                <asp:SqlDataSource ID="calllog" runat="server"></asp:SqlDataSource>
                <br />
                                      </div>
                      
	    </div>
    </form>
		
          
</body>
</html>

Open in new window

 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        user.Text = "you are loggin in as " & System.Security.Principal.WindowsIdentity.GetCurrent.Name
        TextBox1.Attributes.Add("onfocus", "this.value = '';")

    End Sub

    Sub startwatch()
        Page.RegisterStartupScript("SCRIPTNAME", "<script language='javascript'>timedCount();</script>")
    End Sub
    Sub stopwatch()
        Page.RegisterStartupScript("SCRIPTNAME", "<script language='javascript'>stopCounter();</script>")
    End Sub

Open in new window


and the javascript

var t;
var h = '00';
var m = '00';
var s = '00';
var hs = 0;
var dr;
var drcount = 1;

function timedCount() {

    document.getElementById('txt').value = h + ":" + m + ":" + s + ":" + hs;
    hs++;
    if (hs == 10) {
        hs = 00;
        s++;
        s = checkTime(s);
    }
    if (s == 60) {
        s = 00;
        m++;
        m = checkTime(m);
    }
    if (m == 60) {
        m = 00;
        h++;
        h = checkTime(h);
    }
    t = setTimeout("timedCount()", 100);




}

function resetTime() {

    clearTimeout(t);
    h = '00';
    m = '00';
    s = '00';
    hs = 0;
    drcount = 1;
    document.getElementById('txt').value = h + ":" + m + ":" + s + ":" + hs;


}

Open in new window

runnerjp2005Asked:
Who is Participating?
 
iusephpCommented:
I tried it in a simple html and it works fine. There is nothing wrong in your javascript.
sorry, I dont have an environment to test asp.net / vbscript
Not sure abt  Page.RegisterStartupScript("SCRIPTNAME", "<script language='javascript'>timedCount();</script>")

Sorry


<html>

<script>


var t;
var h = '00';
var m = '00';
var s = '00';
var hs = 0;
var dr;
var drcount = 1;

function timedCount() {

    document.getElementById('txt').value = h + ":" + m + ":" + s + ":" + hs;
    hs++;
    if (hs == 10) {
        hs = 00;
        s++;
        s = checkTime(s);
    }
    if (s == 60) {
        s = 00;
        m++;
        m = checkTime(m);
    }
    if (m == 60) {
        m = 00;
        h++;
        h = checkTime(h);
    }
    t = setTimeout("timedCount()", 100);




}

function checkTime(check) {

        if (check < 10) {
            check = '0' + check;
        }
        if (check == 0) {
            check = '00';
        }
        return check;

    }

function resetTime() {

    clearTimeout(t);
    h = '00';
    m = '00';
    s = '00';
    hs = 0;
    drcount = 1;
    document.getElementById('txt').value = h + ":" + m + ":" + s + ":" + hs;


}


</script>
<body>

<input type=button onclick=timedCount() value='start'/>
<input type='text' id='txt'/>
</body>
</html>

Open in new window

0
 
iusephpCommented:
where is the checkTime() ?
0
 
runnerjp2005Author Commented:
sorry it didnt copy
 function checkTime(check) {

        if (check < 10) {
            check = '0' + check;
        }
        if (check == 0) {
            check = '00';
        }
        return check;

    }

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.