0

How i can put variable into json see example

$('.thermometer-noconfig').thermometer({

    percent: 10,   
    speed: 'slow'
})
/* thermometers with config */
$('.thermometer-config').thermometer({

    percent: 10, 
    speed: 'slow'
})

I need instead of a number "10", I need put variable test How I can do that, please help me

2
  • 4
    Did you try just replacing 10 with test ? Commented Apr 3, 2014 at 20:44
  • 2
    Also, this isn't json, these are javascript object literals. Commented Apr 3, 2014 at 20:46

2 Answers 2

1
your_var = 'whatever'; 
$('.thermometer-noconfig').thermometer({

    percent: 10,   
      speed: 'slow'
    })
    /* thermometers with config */
    $('.thermometer-config').thermometer({

      percent: your_var , 
      speed: 'slow'
    })
Sign up to request clarification or add additional context in comments.

Comments

0
var myThing = { percent: 10, speed: 'slow' };

mything.percent="test";

var myJsonThing = JSON.stringify(myThing);

Now I don't know what the 'thermometer' is / or what it needs - but you can pass either of these :

$('.thermometer-config').thermometer(myThing);

Or if it needs the JSON format :

$('.thermometer-config').thermometer(myJsonThing);

The output of the JSON.stringyfy() on myThing is

{ "percent": "test", "speed": "slow" }

, but as you are not passing this data to a service over http, I don't know why you are asking for the json format, have to tell us more if so.

5 Comments

* I see you have removed the reference to json in the question now :P
Hi I need to display some of my calculations as thermometer
but when I insert my calculations in the function, then it stops working
here is it $("#start2").click(function(){ G = $("#test").val(); H = 10; D = 0.2; p_0 = 14.69; T_0 = 293.15; Pi= 3.1415926; S = 0.25*PiDD; V_0 = SH; p = p_0 + G/(144*S); pp0 = p_0/p; st_pp0 = Math.pow(pp0,5./7.); V = V_0 * st_pp0; h = (V_0 - V)/S; st_pp02 = Math.pow(pp0,-2./7.); T = 1.8*T_0*st_pp02-459.67; h2 = h * 156; T2 = 2*(t-40); p2 = 2.5(p-10); $('.thermometer-noconfig').thermometer({ percent: T2 , speed: 'slow' }) / thermometers with config */ $('.thermometer-config').thermometer({ percent: h2 , speed: 'slow' }) });
Hi @user3127698, probally best to ask a new question

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.