I have this:
<select id="prio" class="w60">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
If i select another value, an onchange = function() is called:
var prio = document.getElementById('prio');
var string1 = "Hello";
var string2 = "";
prio.onchange = function ()
{
prioIndex = prio.options[prio.selectedIndex].text;
switch (prioIndex)
{
case '1': prioIndex = " my Friend";
break;
case '2': prioIndex = " my Sister and Brother";
break;
case '3': prioIndex = " my Mom and Dad";
break;
}
alert(prioIndex);
string2 = prioIndex;
}
alert(string2);
The alert inside the function works fine but he will not assign the new String.
alert(string2) shows string2 (undefined).
I want to use string2 outside the function. But i can't because it is never assigned. But I dont know why.
Lets say, i want to use string2 in another onchange function...
var string3;
news.onchange = function ()
{
string3 = string2.concat(' how are you');
alert(string3);
}
and assign it to string3. if I want to use string3 outside the onchange-function it is undefined.