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 6549227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:04:03+00:00 2026-05-25T12:04:03+00:00

Minor issue that I noticed in a Rails app that I use for learning

  • 0

Minor issue that I noticed in a Rails app that I use for learning new stuff.

I have some simple jQuery that I use to display the time elapsed since a start_time and an end_time on a form:

$(document).ready(function() {
    var initial_start = $('#formatted_start_time').val();
    var initial_end   = $('#formatted_end_time').val();
    $("#duration").text(findDuration(initial_start,initial_end));
})

The findDuration() function simply returns a string that says “1 hour 12 minutes,” or something of the ilk based on the contents of the #formatted_start_time and #formatted_end_time fields. This all works as I would expect.

I noticed that the code fires after I submit the form, however, and Web Inspector shows a single js error TypeError: 'undefined' is not an object (evaluating 'startTime.split'), which just refers to the first line in the findDuration() function. The ‘show’ page does not have a #duration element, so the code shouldn’t fire after submitting (or so I thought).

Why is this code running when I click submit and how do I prevent the error?

Edit: The code probably is firing on the ‘show’ page and not actually when I click submit. The issue seems to be that it is firing on a page with no #duration element, as if the show page triggers $(document).ready... for the previous page when it lands on the show page.

  • 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-25T12:04:04+00:00Added an answer on May 25, 2026 at 12:04 pm

    A simple way is to check the current page, and if it matches the one you want to run this on, run it.

    Alternatively, you could just remove the script from the pages you don’t want it to run on, which is a much better way to do it 😛

    $(document).ready(function() {
        if (location.href == 'http://page.you.want/this/to/run.on') {
            var initial_start = $('#formatted_start_time').val();
            var initial_end   = $('#formatted_end_time').val();
            $("#duration").text(findDuration(initial_start,initial_end));
        }
    })
    

    Another alternative to check if the #duration element exists first;

    $(document).ready(function() {
        if ($('#duration').length > 0) {
            var initial_start = $('#formatted_start_time').val();
            var initial_end   = $('#formatted_end_time').val();
            $("#duration").text(findDuration(initial_start,initial_end));
        }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just uploaded my first app to iTunes Connect and noticed that my
Exception handling in php ... I have noticed some quirks that seem to make
I have a minor issue with displaying TextViews in my app while running on
I have a minor issue in handling DateTime in C#. I have designed a
Okay so I've noticed that even though I use the correct path for the
I know this is a minor issue, but why, if you use scaffolding in
I'm running into a minor issue with some ASP.Net code I'm working on. For
Hey, SO, minor issue: I have an NSWindow I am using to report exceptions
I have a method that is performing some arithmetic on a set of UIViews
I am having a minor issue with IE7 (whats New)... I am trying to

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.