Firefox JavaScript parameters passed to function are undefined on event









up vote
0
down vote

favorite












I see some questions previously asked on this topic but have either not been answered or I don't understand the answer.



Why does the following work in ALL browsers except FireFox? When the onplay() event fires, the parameter passed is undefined.



<html>
<head><title></title>
</head>
<body>
<audio id="audioplayer" name="player1" preload="none" onplay="audioStarted(audioplayer[0]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=1" controls> </audio><br/>
<audio id="audioplayer" name="player2" preload="none" onplay="audioStarted(audioplayer[1]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=2" controls> </audio><br/>
<audio id="audioplayer" name="player3" preload="none" onplay="audioStarted(audioplayer[2]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=3" controls> </audio><br/>
<audio id="audioplayer" name="player4" preload="none" onplay="audioStarted(audioplayer[3]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=4" controls> </audio><br/>
</body>

<script>
function audioStarted(thePlayer) alert(thePlayer.src);
</script>
</html>









share|improve this question





















  • You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
    – David Thomas
    Nov 10 at 7:48










  • Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
    – Sytze Visser
    Nov 10 at 9:11















up vote
0
down vote

favorite












I see some questions previously asked on this topic but have either not been answered or I don't understand the answer.



Why does the following work in ALL browsers except FireFox? When the onplay() event fires, the parameter passed is undefined.



<html>
<head><title></title>
</head>
<body>
<audio id="audioplayer" name="player1" preload="none" onplay="audioStarted(audioplayer[0]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=1" controls> </audio><br/>
<audio id="audioplayer" name="player2" preload="none" onplay="audioStarted(audioplayer[1]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=2" controls> </audio><br/>
<audio id="audioplayer" name="player3" preload="none" onplay="audioStarted(audioplayer[2]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=3" controls> </audio><br/>
<audio id="audioplayer" name="player4" preload="none" onplay="audioStarted(audioplayer[3]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=4" controls> </audio><br/>
</body>

<script>
function audioStarted(thePlayer) alert(thePlayer.src);
</script>
</html>









share|improve this question





















  • You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
    – David Thomas
    Nov 10 at 7:48










  • Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
    – Sytze Visser
    Nov 10 at 9:11













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I see some questions previously asked on this topic but have either not been answered or I don't understand the answer.



Why does the following work in ALL browsers except FireFox? When the onplay() event fires, the parameter passed is undefined.



<html>
<head><title></title>
</head>
<body>
<audio id="audioplayer" name="player1" preload="none" onplay="audioStarted(audioplayer[0]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=1" controls> </audio><br/>
<audio id="audioplayer" name="player2" preload="none" onplay="audioStarted(audioplayer[1]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=2" controls> </audio><br/>
<audio id="audioplayer" name="player3" preload="none" onplay="audioStarted(audioplayer[2]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=3" controls> </audio><br/>
<audio id="audioplayer" name="player4" preload="none" onplay="audioStarted(audioplayer[3]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=4" controls> </audio><br/>
</body>

<script>
function audioStarted(thePlayer) alert(thePlayer.src);
</script>
</html>









share|improve this question













I see some questions previously asked on this topic but have either not been answered or I don't understand the answer.



Why does the following work in ALL browsers except FireFox? When the onplay() event fires, the parameter passed is undefined.



<html>
<head><title></title>
</head>
<body>
<audio id="audioplayer" name="player1" preload="none" onplay="audioStarted(audioplayer[0]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=1" controls> </audio><br/>
<audio id="audioplayer" name="player2" preload="none" onplay="audioStarted(audioplayer[1]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=2" controls> </audio><br/>
<audio id="audioplayer" name="player3" preload="none" onplay="audioStarted(audioplayer[2]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=3" controls> </audio><br/>
<audio id="audioplayer" name="player4" preload="none" onplay="audioStarted(audioplayer[3]);" src="http://kerkradio.co.za:8000/audio/beste-luisteraar.mp3?a=4" controls> </audio><br/>
</body>

<script>
function audioStarted(thePlayer) alert(thePlayer.src);
</script>
</html>






javascript firefox undefined






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 10 at 7:45









Sytze Visser

61




61











  • You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
    – David Thomas
    Nov 10 at 7:48










  • Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
    – Sytze Visser
    Nov 10 at 9:11

















  • You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
    – David Thomas
    Nov 10 at 7:48










  • Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
    – Sytze Visser
    Nov 10 at 9:11
















You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
– David Thomas
Nov 10 at 7:48




You have multiple elements with the same id, which is invalid, and you're passing a variable that's undefined in the code you show, and you're trying to access a property of that variable. What are you trying to do?
– David Thomas
Nov 10 at 7:48












Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
– Sytze Visser
Nov 10 at 9:11





Hi Thomas. I am aware of the multiple elements with the same name, hence passing the index counter i.e. audioplayer[0]. Works very well except in FireFox. Have a look at what I am really trying to accomplish here: kerkradio.co.za The code example just simplified what the problem is.
– Sytze Visser
Nov 10 at 9:11













1 Answer
1






active

oldest

votes

















up vote
0
down vote













That it works at all (which I guess it might) is an aberration brought about from javascript's weird hoisting of id's to the global scope (making getElementById oddly redundant). Firefox is quite right to cough this code back up, and I'd be surprised if it really were the case that it works in all other browsers



Try passing the keyword this instead of that audioplayer[n] jive - yours is the sort of situation that this was designed to handle






share|improve this answer




















    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237010%2ffirefox-javascript-parameters-passed-to-function-are-undefined-on-audio-event%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote













    That it works at all (which I guess it might) is an aberration brought about from javascript's weird hoisting of id's to the global scope (making getElementById oddly redundant). Firefox is quite right to cough this code back up, and I'd be surprised if it really were the case that it works in all other browsers



    Try passing the keyword this instead of that audioplayer[n] jive - yours is the sort of situation that this was designed to handle






    share|improve this answer
























      up vote
      0
      down vote













      That it works at all (which I guess it might) is an aberration brought about from javascript's weird hoisting of id's to the global scope (making getElementById oddly redundant). Firefox is quite right to cough this code back up, and I'd be surprised if it really were the case that it works in all other browsers



      Try passing the keyword this instead of that audioplayer[n] jive - yours is the sort of situation that this was designed to handle






      share|improve this answer






















        up vote
        0
        down vote










        up vote
        0
        down vote









        That it works at all (which I guess it might) is an aberration brought about from javascript's weird hoisting of id's to the global scope (making getElementById oddly redundant). Firefox is quite right to cough this code back up, and I'd be surprised if it really were the case that it works in all other browsers



        Try passing the keyword this instead of that audioplayer[n] jive - yours is the sort of situation that this was designed to handle






        share|improve this answer












        That it works at all (which I guess it might) is an aberration brought about from javascript's weird hoisting of id's to the global scope (making getElementById oddly redundant). Firefox is quite right to cough this code back up, and I'd be surprised if it really were the case that it works in all other browsers



        Try passing the keyword this instead of that audioplayer[n] jive - yours is the sort of situation that this was designed to handle







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 10 at 10:07









        lucas

        850717




        850717



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.





            Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


            Please pay close attention to the following guidance:


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53237010%2ffirefox-javascript-parameters-passed-to-function-are-undefined-on-audio-event%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Use pre created SQLite database for Android project in kotlin

            Darth Vader #20

            Ondo