Any Javascript/HTML experts around?

Post a reply

Smilies
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Any Javascript/HTML experts around?

Re: Any Javascript/HTML experts around?

by MoDementia » Sat Aug 09, 2008 6:36 pm

The script actually caters for executing other functions so the new problem is getting it to recognise the .vbs file

Code: Select all

        slider.subscribe("slideEnd", function() {
               ChangeSeek();
            });
The other scripts are assigned at the start

Code: Select all

    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
and inside the script they are assigned to a namespace

I have posted the question here it's driving me crazy not being able to finalise the script :cry: :(

Re: Any Javascript/HTML experts around?

by MoDementia » Sun Aug 03, 2008 5:19 pm

Yeah it sort of make sense.
I guessed it was "nested" so that it didn't have direct access to the document anymore
I'll look closer at the subscribe code and see if i can untangle it
Thanks.

Re: Any Javascript/HTML experts around?

by trixmoto » Sun Aug 03, 2008 4:49 pm

In this case a new function is being created and passed into the "subscribe" function in one go, giving you the "});" notation. This is something which you can do in javascript but I've never seen in any other language. I believe the "subscribe" function is then registering the function that you pass in to be fired by the relevant events. Depending on how the "subscribe" function works, you should be able to register multiple functions to the same event by calling "subscribe" twice. If this is not the case then you'll need to make sure that at the end of the first function you call the second function. Does this help/make sense?

Re: Any Javascript/HTML experts around?

by rovingcowboy » Sat Aug 02, 2008 10:51 am

you might find one already made try these places.

http://www.javascript-2.com/

http://www.dynamicdrive.com

the scripts there are free to use.

Any Javascript/HTML experts around?

by MoDementia » Sat Aug 02, 2008 2:20 am

I have one javascript function executing from an event but I need to trigger an event on another element from that function once the new value is set

I pinched the javascript from a website and it looks different than I'm used to so that may have something to do with it?

Original code is here
I don't understand the format of the code "});" ?
I need to trigger the other event at the end of this section

Code: Select all

slider.subscribe("change", function(offsetFromStart) {

Code: Select all

<script type="text/javascript">
(function() {
    var Event = YAHOO.util.Event,
        Dom   = YAHOO.util.Dom,
        lang  = YAHOO.lang,
        slider, 
        bg="slider-bg", thumb="slider-thumb", 
        valuearea="slider-value", textfield="slider-converted-value"

    // The slider can move 0 pixels up
    var topConstraint = 0;

    // The slider can move 200 pixels down
    var bottomConstraint = 200;

    // Custom scale factor for converting the pixel offset into a real value
    var scaleFactor = 1.5;

    // The amount the slider moves when the value is changed with the arrow
    // keys
    var keyIncrement = 20;

    var tickSize = 20;

    Event.onDOMReady(function() {

        slider = YAHOO.widget.Slider.getHorizSlider(bg, 
                         thumb, topConstraint, bottomConstraint, 20);

        slider.getRealValue = function() {
            return Math.round(this.getValue() * scaleFactor);
        }

        slider.subscribe("change", function(offsetFromStart) {

            var valnode = Dom.get(valuearea);
            var fld = Dom.get(textfield);

            // Display the pixel value of the control
            valnode.innerHTML = offsetFromStart;

            // use the scale factor to convert the pixel offset into a real
            // value
            var actualValue = slider.getRealValue();

            // update the text box with the actual value
            fld.value = actualValue;

            // Update the title attribute on the background.  This helps assistive
            // technology to communicate the state change
            Dom.get(bg).title = "slider value = " + actualValue;

        });

        slider.subscribe("slideStart", function() {
                YAHOO.log("slideStart fired", "warn");
            });

        slider.subscribe("slideEnd", function() {
                YAHOO.log("slideEnd fired", "warn");
            });

        // Listen for keystrokes on the form field that displays the
        // control's value.  While not provided by default, having a
        // form field with the slider is a good way to help keep your
        // application accessible.
        Event.on(textfield, "keydown", function(e) {

            // set the value when the 'return' key is detected
            if (Event.getCharCode(e) === 13) {
                var v = parseFloat(this.value, 10);
                v = (lang.isNumber(v)) ? v : 0;

                // convert the real value into a pixel offset
                slider.setValue(Math.round(v/scaleFactor));
            }
        });
        
        // Use setValue to reset the value to white:
        Event.on("putval", "click", function(e) {
            slider.setValue(100, false); //false here means to animate if possible
        });
        
        // Use the "get" method to get the current offset from the slider's start
        // position in pixels.  By applying the scale factor, we can translate this
        // into a "real value
        Event.on("getval", "click", function(e) {
            YAHOO.log("Current value: "   + slider.getValue() + "\n" + 
                      "Converted value: " + slider.getRealValue(), "info", "example"); 
        });
    });
})();
</script>

Top