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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T15:23:34+00:00 2026-06-05T15:23:34+00:00

I have a javascript that returns a value whenever I choose an option from

  • 0

I have a javascript that returns a value whenever I choose an option from a dropdown menu.

   $(document).ready(function() {
        function calculateVals() { 
            //dropdown menus      
             var valuestart = $("select[name='timestart']").val();
             var valuestop = $("select[name='timestop']").val();

             //create date format          
             var timeStart = new Date("01/01/2007 " + valuestart).getHours();
             var timeEnd = new Date("01/01/2007 " + valuestop).getHours();

             var hourDiff = timeEnd - timeStart;                         

             return hourDiff;  

        }
        $("select").change(calculateVals);
        calculateVals();
    });

The script above returns a number which I need to add to a jquery plugin below. I need to add it to the max option but I get the error calculateVal is not defined.

$(function(){
    $("#slider").slider({
        range: "min",
        value:  8,
        min: 1,
        max: calculateVals(), //my attempt
        step: 1,
        slide: function(event, ui) {
            $("#amount").text(ui.value);
        },
         stop: function(event, ui) {
            $("#notifications").val(ui.value);
        }
    });
    $("#notifications").val( $("#slider").slider("value") );
});
  • 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-05T15:23:35+00:00Added an answer on June 5, 2026 at 3:23 pm

    Move the function to the global scope:

    function calculateVals() {       
        //code here...
        return someResult;                                           
    }
    
    $(document).ready(function() {
            $("select").change(calculateVals);
        calculateVals();
    });
    

    And even better, learn what does DOM ready means, as you misuse it.

    • You should have only one ready handler.
    • Only code relevant to DOM elements should be there.

    Update:

    You can later on change the slider max with:

    $( "#slider").slider("option", "max", calculateVals());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Javascript function that returns the innerHTML of a div. I am
I have a php file that returns a div and a javascript. I want
I have a javascript that calls a function each 1 minute. That function sends
I have a javascript that displays a generated text into a div: document.getElementById('phrase').innerHTML =
I have a javascript that is executed with the onchange event. onchange=showUser(1, this.value) The
I have a javascript function that works as I would like : <script language=javascript
I have the following Javascript function that makes a call to an Asp.Net WebMethod
I have a following javascript that I call from my _form.html.erb. $.ajax({ type: GET,
I have a javascript function that posts data to a validation script and grabs
I have a function that returns an integer (the current reputation score for 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.