Javascript: getting selected value *RESOLVED*
I have a select box in a form:
<select name="score1" id="score1" onChange="scoreImage('insults_generosity', 'score1');">
<option>-5</option>
<option>-4</option>
<option>-3</option>
<option>-2</option>
<option>-1</option>
<option>0</option>
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
There are the following functions:
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
function scoreImage(scorePrefix, formElement) {
var imagePath = 'images/' + scorePrefix + eval('window.document.new_case_file.' + formElement + '.value') + '.gif';
MM_swapImage(scorePrefix,'',imagePath,1);
}
It is supposed to swap the image with the name 'insults_generosity'. The new image is supposed be at the path: images/insults_generosity-5.gif if the selected value is -5 or images/insults_generosity1.gif if the selected value is 1. However it always swaps the image with images/insults_generosity.gif i.e. the selected value is not being concatenated into the filename.
I've used an alert to return the selected value from this form element and it is always blank!
What am I doing wrong?!?!?
DJ