In article <c9**************************@posting.google.com >,
ef*****@epitome.com.sg enlightened us with...
I am trying to write a simple Javascript code to pass value from a
listbox to another field
the following is my code
f=document.forms[0];
window.alert(f.FieldList.options.length)
for(i=0;i<f.FieldList.options.length;i++)
{
if(f.FieldList.options[i].selected){
sReturn=f.FieldList.options[i].value -------> this line doesn't seem
to work.
sReturn+=sReturn +","
window.alert(sReturn)}
}
Target=document.forms[0].RefTargetField.value;
TargetField=eval("window.opener.document.forms[0]." +Target);
TargetField.value=sReturn;
window.close()
Can help me figure out what I need to do to get the selected value to
sReturn?
I assume this is a select that can be multiple. Because there's no other
reason to loop through the options to get the selected one.
Assuming that, you wanted sReturn += f.FieldList.options[i].value and
you wanted to initialize sReturn to the empty string first. Note that
with no other code, I can't see if sReturn was declared OUTSIDE the if
or for block, as it would need to be.
Now, I see no other code, so I can't tell you why it "isn't working".
Especially since I don't know what you mean by that. What isn't working?
What happens? What browser? Did you check for errors? Did you check that
the form element you're accessing has properly formed HTML with values
for the options? It is legal, IIRC, to have options with no values.
Since I have no code here, I can't see if that is the case.
How about a working example or a link?
The best I can do with no other code:
var sReturn=""; // needed here or it is local to the for block and
unavailable when referenced for TargetField.value
f=document.forms[0];
window.alert(f.FieldList.options.length)
for(i=0;i<f.FieldList.options.length;i++)
{
if(f.FieldList.options[i].selected)
{
sReturn+=f.FieldList.options[i].value;
sReturn+=sReturn +",";
window.alert(sReturn);
}
}
Target=document.forms[0].RefTargetField.value;
TargetField=eval("window.opener.document.forms[0]." +Target);
TargetField.value=sReturn;
window.close()
--
--
~kaeli~
To steal ideas from one person is plagiarism; to steal from
many is research.
http://www.ipwebdesign.net/wildAtHeart http://www.ipwebdesign.net/kaelisSpace