Solved

jquery function fires on declaration

Posted on 2014-10-25
2
116 Views
Last Modified: 2014-10-26
This runs out of my "page initialized" function

function SetUpJQSliderElements() {

    var $SizeSlider = $("#SizeSlider").slider({
        min: .5,
        max: 2,
        step: .25,
        animate: "slow",
        value:.75
    })

    $SizeSlider.on("slidechange", function () {
        SizeFactorChange()
    })
    
    var SizeFactorDisplay = $("#SizeFactorDisplay")
}

Open in new window


How might I specify the SizeSlider.on function (SizeFactorChange) so that it does not execute at the time of declaration?
0
Comment
Question by:codequest
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 25

Accepted Solution

by:
Kyle Hamilton earned 500 total points
ID: 40404810
A function declaration defines a function. What you have are two function calls (not declarations), the first one of which is an event listener:

$SizeSlider.on()  <-- function call. The on function has an event listener built into it.

.on(event, callback) <-- arguments: the event, and the callback. The callback function will will be executed when the event happens

On line 11, you have a function which listens for the "slidechange" event. Every time this event happens, the callback function will be executed. In the callback you have a function call to the SizeFactorChange function. This will execute the SizeFactorChange function.

What is the issue, and what do you  want to happen?

If you don't want it to execute, remove it.
0
 
LVL 2

Author Comment

by:codequest
ID: 40405139
Thanks, that jogged me into understanding better what was needed:

function SetUpJQSliderElements() {

    var $MapSizeSlider = $("#MapSizeSlider").slider({
        min: .5,
        max: 2,
        step: .25,
        animate: "slow",
        value: .75,
        change: MapSizeFactorChange
    })

    //$MapSizeSlider.on("slidechange", function () {
    //    MapSizeFactorChange()
    //})
    
    var MapSizeFactorDisplay = $("#MapSizeFactorDisplay")
}

Open in new window

0

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question