0

I am dynamically creating my sliders and in the "Slide" event and "Stop" event I would like to call a function that is defined in the non dynamic content. I can get the functions to work if I create them each time with the slider, but that seems like a lot of redundant code?

Non Dynamic function

    $(document).ready(function() {
var converSecondsToMinutes;

convertSecondsToMinutes = function(secondsEntered){
    var secondsEntered = secondsEntered;

    var time = parseInt(secondsEntered,10);
    time = time < 0 ? 0 : time;

    var minutes = Math.floor(time / 60);
    var seconds = time % 60;

    minutes = minutes < 9 ? "0"+minutes : minutes;
    seconds = seconds < 9 ? "0"+seconds : seconds;
    var newTime = minutes+":"+seconds
    console.log(newTime);
    return newTime
}
});

Dynamic jQuery slider

    <?php
query...
result...
for(...){
?>
<Script>
$( "#slider"+<?php echo $id; ?> ).slider({ 
            animate: true ,
            value: 0,
            min: 0,
            //dynamic grab this
            max: <?php echo $playtime_seconds; ?>,
            step: 0.01,
            start: function( event, ui ) {
                ....
            },
            slide: function( event, ui ) {
                audio = ....
                audio.currentTime = ui.value;
                progress_seconds = parseFloat(audio.currentTime.toFixed(2));
                progress_seconds = $(function(){convertSecondsToMinutes(progress_seconds);});

                $('#progress_seconds'+<?php echo $id; ?>).html(progress_seconds);

            },
            stop: function( event, ui ) {
                ....
                }
            }

        });


    });

}

I cut and paste the parts of the code that were important to the question.

This is the line that is not working: $('#progress_seconds'+).html(progress_seconds);

0

1 Answer 1

1

You edited just after I commented, so my comment no longer made sense, the $(function(){ part of your code is not necessary, try just using:

progress_seconds = converSecondsToMinutes(progress_seconds);

And spelling errors in code are a real issue with me, conver has a t at the end.

There is also no need to wrap your function in $(document).ready(), declare it like this:

function convertSecondsToMinutes(secondsEntered)
{
    var time = ...
    ...
}
2
  • Sorry, still get this error: Uncaught ReferenceError: convertSecondsToMinutes is not defined Nov 9, 2012 at 19:41
  • Have you changed it to convert both in the snippet I posted and the function declaration?
    – Pete Uh
    Nov 9, 2012 at 23:27

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.