By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,911 Members | 1,170 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,911 IT Pros & Developers. It's quick & easy.

How I extract value from selected arrays

P: n/a
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?

Thanks
Jul 23 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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

Jul 23 '05 #2

P: n/a
ef*****@epitome.com.sg (Fendi Baba) wrote in message news:<c9**************************@posting.google. com>...
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?

Thanks

That line that you question, works for me. Perhaps there's an error
in your HTML for the select box.
Jul 23 '05 #3

P: n/a
br*************@glic.com (bruce) wrote in message news:<d3**************************@posting.google. com>...
ef*****@epitome.com.sg (Fendi Baba) wrote in message news:<c9**************************@posting.google. com>...
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?

Thanks

That line that you question, works for me. Perhaps there's an error
in your HTML for the select box.

Thanks. As it turn out the field had an error. Thanks for the response
Jul 23 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.