javaScript question

S

Scott

I have the following function below in my ASP that I am
having a problem with, because I'm not that familiar with
javaScript. What I want to know is how can I tell that I
am at the end of my For-Loop, so I can prevent an extra
comma from being appended to lstRescipients variable (line
7)?

1 function getRecipients(){
2 var lstRecipients = "";
3 var lst = document.getElementById
("lstEmails");
4 for(var i=0;i<lst.options.length;i++){
5 //if (lst.options.selected){
6 lstRecipients +=
lst.options.value;
7 lstRecipients += ",";
8 //alert(i);
9 //alert(lstRecipients);
10 //}
11 }
12 return lstRecipients;
13 }
 
V

Vilmar Brazão de Oliveira

hi,
why don't you make this:
if(i == lst.options.length)
{
actionX;
actionJJHJ;
or break the for loop, thus:
break;
}
I hope that helps you.

--

««««««««»»»»»»»»»»»»»»
Vlmar Brazão de Oliveira
Desenvolvimento Web
HI-TEC
 
R

Ray at

This isn't the right group for javascript issues. .scripting.jscript is a
decent one for such questions.

Ray at work
 
H

Harag

I have to sort of 50/50 disagree with you Ray.

This is an ASP group which can be both coded in VBscipt & javascript,
because most people code in VBscript thats what we see the most here.

But I do agree that the other group would get a better response
because more people in that group will know javascript more than the
people in this group.

I myself am currently learning Jscript/Javascript and will post
questions in the other group about problems in that language more.

This is not a knock at you as I've seen alot of your posts and your
very helpful (even to me in the past :))

Al


This isn't the right group for javascript issues. .scripting.jscript is a
decent one for such questions.

Ray at work

Scott said:
I have the following function below in my ASP that I am
having a problem with, because I'm not that familiar with
javaScript. What I want to know is how can I tell that I
am at the end of my For-Loop, so I can prevent an extra
comma from being appended to lstRescipients variable (line
7)?

1 function getRecipients(){
2 var lstRecipients = "";
3 var lst = document.getElementById
("lstEmails");
4 for(var i=0;i<lst.options.length;i++){
5 //if (lst.options.selected){
6 lstRecipients +=
lst.options.value;
7 lstRecipients += ",";
8 //alert(i);
9 //alert(lstRecipients);
10 //}
11 }
12 return lstRecipients;
13 }

 
H

Harag

oops, just noticed he's using client side code, so yes the other group
will be better as ASP is a serverside group.

Al.


This isn't the right group for javascript issues. .scripting.jscript is a
decent one for such questions.

Ray at work

Scott said:
I have the following function below in my ASP that I am
having a problem with, because I'm not that familiar with
javaScript. What I want to know is how can I tell that I
am at the end of my For-Loop, so I can prevent an extra
comma from being appended to lstRescipients variable (line
7)?

1 function getRecipients(){
2 var lstRecipients = "";
3 var lst = document.getElementById
("lstEmails");
4 for(var i=0;i<lst.options.length;i++){
5 //if (lst.options.selected){
6 lstRecipients +=
lst.options.value;
7 lstRecipients += ",";
8 //alert(i);
9 //alert(lstRecipients);
10 //}
11 }
12 return lstRecipients;
13 }

 
R

Ray at

I wish there were more <%@ language=jscript %> posts. I use vbscript, but I
like to look at jscript code more for some reason. :]

Ray at home
 
H

Harag

lol, well you can look at mine all the time if you wish, I just
converted over to Jscript ASP and learning more every day... I've now
started posting in

comp.lang.javascript
ms.public.scipting.jscript

I needed to learn how to do client side coding and since javascript is
the choice language for that I thought I'd best learn it so I can code
it from scratch rather than find other peoples and "play" with it. So
I'm now coding in Jscript server-side where possible.

Al.


I wish there were more <%@ language=jscript %> posts. I use vbscript, but I
like to look at jscript code more for some reason. :]

Ray at home

Harag said:
oops, just noticed he's using client side code, so yes the other group
will be better as ASP is a serverside group.

Al.
 
D

Dave Anderson

Ray at said:
I wish there were more <%@ language=jscript %> posts. I
use vbscript, but I like to look at jscript code more
for some reason. :]

I, for one, make every effort to respond with JScript and VBScript solutions
when I post in here. We're 100% JScript over here, FWIW.



--
Dave Anderson

Unsolicited commercial email will be read at a cost of $500 per message. Use
of this email address implies consent to these terms. Please do not contact
me directly or ask me to contact you directly for assistance. If your
question is worth asking, it's worth posting.
 
G

Guest

Hi,

You would need to add one more if statement around line 7
that checks to see if your loop variable (i) is at the
last item you are checking.

Try:
if(i<lst.options.length){
lstRecipients += ",";
}

That should work fine.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top