I have a function that accesses an input
element and updates its value using the following line of code:
eval('document.forms[0].telephone').value = $telephone[$i];
Now, I need to transfer this value to a span
, but I'm having trouble referencing it correctly. The current input
has both a name
and an id
of "country", and I suspect that my eval()
is targeting the name
.
The span
does not have a name
, but instead uses a class called tel-prefix
.
I've attempted various approaches to reference it (and different combinations), but none seem to be working:
eval('document.forms[0].tel-prefix').value = $telephone[$i];
eval('.tel-prefix').value = $telephone[$i];
eval('.tel-prefix').text= $telephone[$i];
$('.tel-prefix').value = $telephone[$i];
$('.tel-prefix').value($telephone[$i]);
Is there a way for my eval()
to update the value of my span
?
Complete JS Code
$telephone = new Array(4)
$telephone [0] = "+93"
...
$telephone [246] = "+260"
$telephone [247] = "+263"
function getTelephone($selectedIndex) {
$selectBox = document.forms[0].spch_country;
if ($selectBox.options[$selectedIndex].value != 'none') {
for ($j = 0, $i = $selectedIndex; $i < $selectedIndex + 1; $j++, $i++) {
eval('document.forms[0].tel-prefix').value = $telephone[$i];
}
}
}