0

new week, new problems with my project, so I'll be glad to see any suggested solutions of yours :) .

The obstacle consists in that I have a slider made up with jQuery UI and I also have a JavaScript function which needs to get jQ's values of slider's increase and respectively decrease and store it in a variable.
So far, I was able to make a slider and stream it's parameters to an html <p><span>.. construction but it's not enough because this reflects only on the output of the document and has nothing to do with my js code/functions which I'm planning to develop later. Up to now, my code looks something like this:

 $(function(){
  $(".slider").slider()
  $("#angle").slider({
    value:0,
    min:0,
    max:250,
    step:0.5,
    slide: function (event, ui){
       $( "#angres" ).html( ui.value );
       $("fang").change(function(){
        $("ang").val($(this).val());
       });
      }
    });
   $("#angres").html($('#angle').slider('value'));

Ok, this $( "#angres" ).html( ui.value ); works absolutely fine and displays the 'movement' of the slider on the document, with a changing value. However, I need to have exactly the same value in a parameter, to use it with js. I need to store this change in a variable. How to do it? :)

8
  • $(".slider").slider() shoud end with ; Commented Aug 4, 2015 at 15:20
  • @Reflective Most of the time ; are optional in JS. Commented Aug 4, 2015 at 15:20
  • 1
    Probably you are a trouble-lover if you prefer to avoid the correct syntax. You should be aware of tha fact that your code is executed client side which means different browsers, different OS, different devices and other different things that you could even not imagine :) Commented Aug 4, 2015 at 15:24
  • 2
    The concept, "connecting jQuery with JavaScript" doesn't make a lot of sense; jQuery is JavaScript. It's really not clear what it is you want to do. Commented Aug 4, 2015 at 15:24
  • 1
    @Reflective Comma insertion is a rigorously-specified aspect of JavaScript syntax. It does not vary among implementations in modern environments. Commented Aug 4, 2015 at 15:26

1 Answer 1

1

It's all about assignig a variable to the global window scope.
Modify it inside your slider (increase, decrease, whatever)
Any other "JS" (jQuery is JavaScript) function will be able, on call, to read that variable value (state)

var counter = 0; // Global variable

function getCounterValue() {
    alert( counter );      // Will always give you the modified `counter` value
}
// Call the above function wherever you want

jQuery(function($) { // jQuery. DOM ready

     // Slider >> increment `counter`, decrement `counter`...
     // ...other super jQuery DOM ready stuff
});
Sign up to request clarification or add additional context in comments.

1 Comment

I will just suggest to store the value as data in the related tag which will keep the globality but the value will be stored in a related to the purpose place.

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.