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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:14:36+00:00 2026-06-14T05:14:36+00:00

JSFiddle : http://jsfiddle.net/veksen/7TRgE/1/ If I call the variable value from inside my function, it

  • 0

JSFiddle : http://jsfiddle.net/veksen/7TRgE/1/

If I call the variable value from inside my function, it works. However, it doesn’t if I call it outside of the function.

I feel like it has something to do with change, as it is first assigned ok, but won’t change.

var diff_res = { norm:0, nm:-40, hell:-100 };
var difficulty = "hell"; 
$("select").change(function () {
    difficulty = $("select option:selected").val();
    $(".inside").text(diff_res[difficulty]);
})
.change();

var char_fr = 30;
char_fr += diff_res[difficulty];

$(".outside").text(diff_res[difficulty]);

​

  • 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-14T05:14:37+00:00Added an answer on June 14, 2026 at 5:14 am

    UPDATE:

    By re-executing, I meant something like this:

    $(document).ready(function () {
        'use strict';
        var diff_res = {
                norm: 0,
                nm: -40,
                hell: -100
            },
            difficulty = "hell",
            char_fr = 30,
            changeOutside = function changeOutside() {
                $(".outside").text(diff_res[difficulty]);
            };
        $("select").change(function () {
            difficulty = $("select option:selected").val();
            $(".inside").text(diff_res[difficulty]);
            changeOutside();
        }).change();
        char_fr += diff_res[difficulty];
    });
    

    The point was that $(".outside").text(diff_res[difficulty]); is only being executed once, when the DOM is loaded, which is why the text() is initially set to -100. To change the .outside again, you need to re-run $(".outside").text(diff_res[difficulty]);

    ORIGINAL:

    Your problem is that:

    $(".outside").text(diff_res[difficulty]);
    

    is only executed one time, in the $(document).ready() function. If you want it to change more often, you’ll need to re-execute that in your change handler.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://jsfiddle.net/yTkTd/ Another function with a class works perfectly, but this one seems to be
http://jsfiddle.net/JamesKyle/HQDu6/ I've created a short function based on Mathias Bynens Optimization of the Google
Jsfiddle: http://jsfiddle.net/87YGW/ At present I have to click tab 1 to show content however
jsFiddle: http://jsfiddle.net/fThMa/2/ Clicking inside the note / rend text fields and then double clicking
Jsfiddle: http://jsfiddle.net/yJJs7/ Javascript: function main(){ var centerx=250; var centery=250; var degrees=0; var div=document.getElementById('test'); var
JsFiddle: http://jsfiddle.net/fPsK6/2/ Why visible binding doesn't work?
In this JsFiddle : http://jsfiddle.net/maxl/mCXND/ (copied and modified from http://jsfiddle.net/ud3323/XMgwV/ ) I try to
In this jsFiddle http://jsfiddle.net/littlesandra88/RBU8K/ have I the following code function addRemove(id) { alert(1); $('#'+id).toggle(function()
jsfiddle: http://jsfiddle.net/MFUw3/5/ jQuery: function showDiv() { if ($(window).scrollTop() > 610) { $(.a).css({position: fixed, top:
link to jsFiddle : http://jsfiddle.net/k8wYF/1/ (working) var count; $(#sortable).sortable({ start : function(){ count =

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.