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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T08:47:15+00:00 2026-06-02T08:47:15+00:00

My problem is fairly simple to explain yet a little tricky to implement. Logically

  • 0

My problem is fairly simple to explain yet a little tricky to implement. Logically it seems very possible but im a little stuck.

Objective/purpose:
I have my first SELECT named “hour” and a second SELECT named “rec_hour”. Each have the same values. See HTML code below:

<select id="hour">
  <option value="0">00</option>
  <option value="1">01</option>
  <option value="2">02</option>
  <!-- This would go up to 23 -->
</select>

<select id="rec_hour">
   <option value="0">00</option>
   <option value="1">01</option>
   <option value="2">02</option>
 <!-- This would go up to 23 -->
</select>

I receive a variable from a PHP file “$hours” which contains a integer value ranging from 0 to 24. Now, I want to get that value of hours, lets say its 6 for this scenerio, and subtract this value in the second SELECT (rec_hour).

So in essence, if my returned variable is 6. and i choose say 10 from the first select (hour) then i want the second select to show/select the value that is 10-6 which is 4.

I hope that makes sense..

I have tried the script below out of desperation but to no avail:

    $(document).ready(function() {

    $("#hour").change(function() {
        var myHour = $(this).val();
        var Subtra = 10;
        var recHour = myHour - Subtra;

       $("#rec_hour").val = recHour;
       $("#rec_hour").text(recHour); 
     }
  });

});

My code above im using “Subtra” as a litmus test value.. this would actually change based on my php result.

UPDATE:

All i really want to do is this..

I receive a time (hours only) say 2 -> refers to 2am (14 would be 2pm) n then my php will calculate hours to find out how long a journy will take. For instance say tht is 6 hours.. then i want to show the user 6 hours behind from 2am..which is 8pm.. i.e. you should leave home at 8pm.. you follow? or am i confusing?

  • 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-06-02T08:47:17+00:00Added an answer on June 2, 2026 at 8:47 am

    Set the value of rec_hour using .val(). Also note there was a few syntax errors in your code. You had an extra curly brace. Also you want to handle the case where subtra > myHour, using the abs value function.

    Corrected Code:

    $(document).ready(function() {
    
        $("#hour").change(function() {
            var myHour = $(this).val();
            var Subtra = 4;
            var recHour = Math.abs(Subtra - myHour);
           $("#rec_hour").val(recHour);
         });
    });
    

    Original With Errors Noted:

        $(document).ready(function() {
    
        $("#hour").change(function() {
            var myHour = $(this).val();
            var Subtra = 10;
            var recHour = myHour - Subtra;  //handle Subtra > myHour with abs()
    
           $("#rec_hour").val = recHour;
           $("#rec_hour").text(recHour); 
         } //This curly brace is not needed
      });
    
    });
    

    Demo: http://jsfiddle.net/FdW4w/3/

    I gave some more descriptive variables names and applied the math. The fiddle is also updated to reflect this.

      $(document).ready(function() {
    
        $("#arrival").change(function() {
            var arrivalTime = $(this).val();
           $("#depart").val(getDepartTime(10, arrivalTime));
         });
    });
    
          function getDepartTime(journeyDuration, arrivalTime){
              var departTime = 0;
              if(journeyDuration > arrivalTime){
                 departTime = 24 - (Math.abs(journeyDuration - arrivalTime));             
              }else{
                 departTime = arrivalTime -journeyDuration;
              }
              return departTime;
          }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a fairly simple problem to me but I have been having
I'm having a very simple problem, which can be solved fairly simple but for
I'm working on a fairly simple console application but I got one little problem.
I have fairly simple problem but I can not think of the simple solution.
I am learning LINQ and this seems like a fairly simple problem. I have
I have a fairly simple regex problem for a little personal experiment that I
I want to do something that seems fairly simple. I get results but the
This is a fairly simple problem but I can't find a solution. I write
I trying to figure out how to solve this (fairly) simple problem but I
I have a problem building a fairly simple local CGO project. Consider this very

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.