Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7696987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:54:27+00:00 2026-05-31T21:54:27+00:00

I am trying to test the following JavaScript code, which is meant to keep

  • 0

I am trying to test the following JavaScript code, which is meant to keep track of the timing of user responses on a multiple choice survey:

document.onclick = function(e) {

    var event = e || window.event;    
    var target = e.target || e.srcElement;

    //time tracking 
    var ClickTrackDate = new Date;
    var ClickData = ""; 
    ClickData = target.id + "=" + ClickTrackDate.getUTCHours() + ":" + 
        ClickTrackDate.getUTCMinutes() + ":" +
        ClickTrackDate.getUTCSeconds() +";";

    document.getElementById("txtTest").value += ClickData;
    alert(target.id); // for testing
}

Usually target.id equals to the the id of the clicked element, as you would expect, but sometimes target.id is empty, seemingly at random, any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:54:28+00:00Added an answer on May 31, 2026 at 9:54 pm

    Probably because the element that was clicked didn’t have an ID. This will happen for example if you have HTML like this:

    <div id="example">This is some <b>example</b> text.</div>
    

    and someone clicks on the boldface word “example”, so that the event target will be the b element instead of the div.

    You could try walking up the DOM tree until you find an element that does have an ID, something like this:

    var target = e.target || e.srcElement;
    
    while (target && !target.id) {
        target = target.parentNode;
    }
    // at this point target either has an ID or is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code, trying to test out WebWorkers. I have an index.html
I've ran into a problem while trying to test following IRepository based on NHibernate:
I'm new to rails and cucumber and I'm trying to test the following scenario
Following on from this question...I'm trying to unit test the following scenario: I have
I have written the following simple test in trying to learn Castle Windsor's Fluent
I'm trying to simply test my RESTful API with cURL. Using the following invocation:
I'm trying to execute the following line: exit | sqlplus username/password@sid @test.sql Works great
I am trying to remove the attribute xmlns=http://webdev2003.test.com from the following xml using xsl/xslt,
I'm trying to accomplish the following layout, http://www.rae-mx.com/test/css-layout.jpg and I'm almost there, except for
just trying to test for equality in this piece of code, but getting a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.