?
Solved

javascript stopwatch

Posted on 2011-05-12
3
Medium Priority
?
496 Views
Last Modified: 2012-06-27
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

0
Comment
Question by:runnerjp2005
  • 2
3 Comments
 
LVL 1

Expert Comment

by:iusephp
ID: 35745152
where is the checkTime() ?
0
 

Author Comment

by:runnerjp2005
ID: 35745222
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
 
LVL 1

Accepted Solution

by:
iusephp earned 2000 total points
ID: 35745246
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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question