Alert if a variable is is undefined












0















Following function gets a value sp_value from radio button if checked.



function spk() {
if (document.getElementById('sp1').checked) {
sp_value = document.getElementById('sp1').value;
} else if (document.getElementById('sp2').checked) {
sp_value = document.getElementById('sp2').value;
} else if (document.getElementById('sp3').checked) {
sp_value = document.getElementById('sp3').value;
}
}


And put the value sp_value in audio source of following function



function PlayVerse(surat, n) {
var aud = document.getElementById("myaudio");
aud.src = "http://data.quranacademy.com/AUDIOS/VerseByVerse/Media-" +
sp_value + "/01_" + TxtFormat(surat, "000") + "_" + TxtFormat(n, "000") + ".mp3";

var x = document.getElementsByTagName("IMG");
var i;
for (i = 0; i < x.length; i++) {
x[i].style = 'display: inline-block; border: 1px solid #ddd; border-radius: 4px; padding: 5px;';
}
}


Now I want to alert a message when user click on function PlayVerse if the radio button is unchecked or you can say the sp_Value is undefined.










share|improve this question




















  • 1





    if (typeof sp_Value === "undefined") {...}

    – Rafael Mora
    Nov 24 '18 at 11:49






  • 1





    Or equivalently, more concisely, just if (sp_Value === undefined)

    – Robin Zigmond
    Nov 24 '18 at 11:52
















0















Following function gets a value sp_value from radio button if checked.



function spk() {
if (document.getElementById('sp1').checked) {
sp_value = document.getElementById('sp1').value;
} else if (document.getElementById('sp2').checked) {
sp_value = document.getElementById('sp2').value;
} else if (document.getElementById('sp3').checked) {
sp_value = document.getElementById('sp3').value;
}
}


And put the value sp_value in audio source of following function



function PlayVerse(surat, n) {
var aud = document.getElementById("myaudio");
aud.src = "http://data.quranacademy.com/AUDIOS/VerseByVerse/Media-" +
sp_value + "/01_" + TxtFormat(surat, "000") + "_" + TxtFormat(n, "000") + ".mp3";

var x = document.getElementsByTagName("IMG");
var i;
for (i = 0; i < x.length; i++) {
x[i].style = 'display: inline-block; border: 1px solid #ddd; border-radius: 4px; padding: 5px;';
}
}


Now I want to alert a message when user click on function PlayVerse if the radio button is unchecked or you can say the sp_Value is undefined.










share|improve this question




















  • 1





    if (typeof sp_Value === "undefined") {...}

    – Rafael Mora
    Nov 24 '18 at 11:49






  • 1





    Or equivalently, more concisely, just if (sp_Value === undefined)

    – Robin Zigmond
    Nov 24 '18 at 11:52














0












0








0








Following function gets a value sp_value from radio button if checked.



function spk() {
if (document.getElementById('sp1').checked) {
sp_value = document.getElementById('sp1').value;
} else if (document.getElementById('sp2').checked) {
sp_value = document.getElementById('sp2').value;
} else if (document.getElementById('sp3').checked) {
sp_value = document.getElementById('sp3').value;
}
}


And put the value sp_value in audio source of following function



function PlayVerse(surat, n) {
var aud = document.getElementById("myaudio");
aud.src = "http://data.quranacademy.com/AUDIOS/VerseByVerse/Media-" +
sp_value + "/01_" + TxtFormat(surat, "000") + "_" + TxtFormat(n, "000") + ".mp3";

var x = document.getElementsByTagName("IMG");
var i;
for (i = 0; i < x.length; i++) {
x[i].style = 'display: inline-block; border: 1px solid #ddd; border-radius: 4px; padding: 5px;';
}
}


Now I want to alert a message when user click on function PlayVerse if the radio button is unchecked or you can say the sp_Value is undefined.










share|improve this question
















Following function gets a value sp_value from radio button if checked.



function spk() {
if (document.getElementById('sp1').checked) {
sp_value = document.getElementById('sp1').value;
} else if (document.getElementById('sp2').checked) {
sp_value = document.getElementById('sp2').value;
} else if (document.getElementById('sp3').checked) {
sp_value = document.getElementById('sp3').value;
}
}


And put the value sp_value in audio source of following function



function PlayVerse(surat, n) {
var aud = document.getElementById("myaudio");
aud.src = "http://data.quranacademy.com/AUDIOS/VerseByVerse/Media-" +
sp_value + "/01_" + TxtFormat(surat, "000") + "_" + TxtFormat(n, "000") + ".mp3";

var x = document.getElementsByTagName("IMG");
var i;
for (i = 0; i < x.length; i++) {
x[i].style = 'display: inline-block; border: 1px solid #ddd; border-radius: 4px; padding: 5px;';
}
}


Now I want to alert a message when user click on function PlayVerse if the radio button is unchecked or you can say the sp_Value is undefined.







javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 11:54









Foo

1




1










asked Nov 24 '18 at 11:44









M Arif ShahidM Arif Shahid

1




1








  • 1





    if (typeof sp_Value === "undefined") {...}

    – Rafael Mora
    Nov 24 '18 at 11:49






  • 1





    Or equivalently, more concisely, just if (sp_Value === undefined)

    – Robin Zigmond
    Nov 24 '18 at 11:52














  • 1





    if (typeof sp_Value === "undefined") {...}

    – Rafael Mora
    Nov 24 '18 at 11:49






  • 1





    Or equivalently, more concisely, just if (sp_Value === undefined)

    – Robin Zigmond
    Nov 24 '18 at 11:52








1




1





if (typeof sp_Value === "undefined") {...}

– Rafael Mora
Nov 24 '18 at 11:49





if (typeof sp_Value === "undefined") {...}

– Rafael Mora
Nov 24 '18 at 11:49




1




1





Or equivalently, more concisely, just if (sp_Value === undefined)

– Robin Zigmond
Nov 24 '18 at 11:52





Or equivalently, more concisely, just if (sp_Value === undefined)

– Robin Zigmond
Nov 24 '18 at 11:52












1 Answer
1






active

oldest

votes


















0














You only need to check if sp_value is not empty when calling PlayVerse():



if(sp_value) {
PlayVerse(surat, n);
} else {
alert("Please, select a value");
}


I hope that helps :-D






share|improve this answer


























  • Will you please explain bit more that in which function I need to type above said script or I should type it separately??

    – M Arif Shahid
    Nov 26 '18 at 4:32











  • You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

    – CryptoBird
    Nov 26 '18 at 12:50











  • if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

    – CryptoBird
    Nov 26 '18 at 12:50











  • If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

    – CryptoBird
    Nov 26 '18 at 12:52











  • Thanks bro, but I have fixed the issue by typing else script..

    – M Arif Shahid
    Nov 27 '18 at 16:17











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
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457771%2falert-if-a-variable-is-is-undefined%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









0














You only need to check if sp_value is not empty when calling PlayVerse():



if(sp_value) {
PlayVerse(surat, n);
} else {
alert("Please, select a value");
}


I hope that helps :-D






share|improve this answer


























  • Will you please explain bit more that in which function I need to type above said script or I should type it separately??

    – M Arif Shahid
    Nov 26 '18 at 4:32











  • You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

    – CryptoBird
    Nov 26 '18 at 12:50











  • if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

    – CryptoBird
    Nov 26 '18 at 12:50











  • If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

    – CryptoBird
    Nov 26 '18 at 12:52











  • Thanks bro, but I have fixed the issue by typing else script..

    – M Arif Shahid
    Nov 27 '18 at 16:17
















0














You only need to check if sp_value is not empty when calling PlayVerse():



if(sp_value) {
PlayVerse(surat, n);
} else {
alert("Please, select a value");
}


I hope that helps :-D






share|improve this answer


























  • Will you please explain bit more that in which function I need to type above said script or I should type it separately??

    – M Arif Shahid
    Nov 26 '18 at 4:32











  • You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

    – CryptoBird
    Nov 26 '18 at 12:50











  • if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

    – CryptoBird
    Nov 26 '18 at 12:50











  • If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

    – CryptoBird
    Nov 26 '18 at 12:52











  • Thanks bro, but I have fixed the issue by typing else script..

    – M Arif Shahid
    Nov 27 '18 at 16:17














0












0








0







You only need to check if sp_value is not empty when calling PlayVerse():



if(sp_value) {
PlayVerse(surat, n);
} else {
alert("Please, select a value");
}


I hope that helps :-D






share|improve this answer















You only need to check if sp_value is not empty when calling PlayVerse():



if(sp_value) {
PlayVerse(surat, n);
} else {
alert("Please, select a value");
}


I hope that helps :-D







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 24 '18 at 16:16

























answered Nov 24 '18 at 16:10









CryptoBirdCryptoBird

16012




16012













  • Will you please explain bit more that in which function I need to type above said script or I should type it separately??

    – M Arif Shahid
    Nov 26 '18 at 4:32











  • You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

    – CryptoBird
    Nov 26 '18 at 12:50











  • if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

    – CryptoBird
    Nov 26 '18 at 12:50











  • If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

    – CryptoBird
    Nov 26 '18 at 12:52











  • Thanks bro, but I have fixed the issue by typing else script..

    – M Arif Shahid
    Nov 27 '18 at 16:17



















  • Will you please explain bit more that in which function I need to type above said script or I should type it separately??

    – M Arif Shahid
    Nov 26 '18 at 4:32











  • You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

    – CryptoBird
    Nov 26 '18 at 12:50











  • if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

    – CryptoBird
    Nov 26 '18 at 12:50











  • If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

    – CryptoBird
    Nov 26 '18 at 12:52











  • Thanks bro, but I have fixed the issue by typing else script..

    – M Arif Shahid
    Nov 27 '18 at 16:17

















Will you please explain bit more that in which function I need to type above said script or I should type it separately??

– M Arif Shahid
Nov 26 '18 at 4:32





Will you please explain bit more that in which function I need to type above said script or I should type it separately??

– M Arif Shahid
Nov 26 '18 at 4:32













You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

– CryptoBird
Nov 26 '18 at 12:50





You should use the code above whenever you would like to call PlayVerse(surat, n);. In other words, you should replace PlayVerse(surat, n); with :

– CryptoBird
Nov 26 '18 at 12:50













if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

– CryptoBird
Nov 26 '18 at 12:50





if(sp_value) { PlayVerse(surat, n); } else { alert("Please, select a value"); }

– CryptoBird
Nov 26 '18 at 12:50













If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

– CryptoBird
Nov 26 '18 at 12:52





If that didn't make sense to you, please, attach to whole JS file to edit it for you :-D

– CryptoBird
Nov 26 '18 at 12:52













Thanks bro, but I have fixed the issue by typing else script..

– M Arif Shahid
Nov 27 '18 at 16:17





Thanks bro, but I have fixed the issue by typing else script..

– M Arif Shahid
Nov 27 '18 at 16:17




















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.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53457771%2falert-if-a-variable-is-is-undefined%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

Wiesbaden

Marschland

Dieringhausen