I have a variable that I would like to use in another function but do not know how to call it correctly. External JS file:
<script>
function search ()
{
var subscriptionId = "";
if (document.getElementById('deleteyes').checked)
{
alert(subscriptionId);
}
}
<script>
HTML file:
<script>
$(document).ready(function() {
$.getJSON(ravenUrl + '/indexes/dynamic/Subscriptions?query=Email%253A' + email, function(json) {
subscriptions = json.Results;
var html = '';
for (var i in json.Results) {
html += '<option value="' + i + '">Edit "' + json.Results[i].Name + '"</option>';
}
$('#subscriptionSelector').append(html);
});
$("#subscriptionSelector").change(function() { //alert('#forumSelector');
var subscriptionIndex = $(this).val();
var subscriptionId = subscriptions[subscriptionIndex]["@metadata"]["@id"].substring(7);
alert(subscriptionId);
});
}
</script>
<body>
<script type="text/javascript" src="externaljsfile.js"></script>
<p>create / edit subscription</p>
<select id="subscriptionSelector"><option selected="true" value="-1">Create new</option></select>
<p>delete subscription</p>
<div style="margin-left:35px;margin-top:6px;float:left;"><input type="radio" name="delete" id="deleteno" class="div1" checked />no</div>
<div style="margin-left:35px;margin-top:6px;float:left;"><input type="radio" name="delete" id="deleteyes" class="div1"/>yes</div>
</body>
The alert(subscriptionId) is generated correctly in the javascript from the html file but the alert in the external js file is obviously not generating the correct subscriptionId.
I realize that this might be a very simple problem but I am at a skill level where I can't even perform searches to find answers on problems related to javascript so please be patient. Thank you in advance.