Solved

jquery function fires on declaration

Posted on 2014-10-25
2
115 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Function after success of Jquery/AJAX action 9 45
Setting up JqueryUI with MVC 5 in Visual Studio 5 50
toggle content 12 24
GitHub 1 9
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 create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
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…

749 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