Firefox JavaScript parameters passed to function are undefined on event
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
add a comment |
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
You have multiple elements with the sameid
, 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 '18 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 '18 at 9:11
add a comment |
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
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
javascript firefox undefined
asked Nov 10 '18 at 7:45
Sytze Visser
61
61
You have multiple elements with the sameid
, 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 '18 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 '18 at 9:11
add a comment |
You have multiple elements with the sameid
, 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 '18 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 '18 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 '18 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 '18 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 '18 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 '18 at 9:11
add a comment |
1 Answer
1
active
oldest
votes
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
add a comment |
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',
autoActivateHeartbeat: false,
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
add a comment |
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
add a comment |
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
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
answered Nov 10 '18 at 10:07
lucas
875717
875717
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 '18 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 '18 at 9:11