Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > javaScript question

Reply
Thread Tools

javaScript question

 
 
Scott
Guest
Posts: n/a
 
      01-13-2004
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[i].selected){
6 lstRecipients +=
lst.options[i].value;
7 lstRecipients += ",";
8 //alert(i);
9 //alert(lstRecipients);
10 //}
11 }
12 return lstRecipients;
13 }

 
Reply With Quote
 
 
 
 
Vilmar Brazão de Oliveira
Guest
Posts: n/a
 
      01-13-2004
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
"Scott" <(E-Mail Removed)> escreveu na mensagem
news:033501c3da0e$54fb79b0$(E-Mail Removed)...
> 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[i].selected){
> 6 lstRecipients +=
> lst.options[i].value;
> 7 lstRecipients += ",";
> 8 //alert(i);
> 9 //alert(lstRecipients);
> 10 //}
> 11 }
> 12 return lstRecipients;
> 13 }
>



 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      01-13-2004
This isn't the right group for javascript issues. .scripting.jscript is a
decent one for such questions.

Ray at work

"Scott" <(E-Mail Removed)> wrote in message
news:033501c3da0e$54fb79b0$(E-Mail Removed)...
> 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[i].selected){
> 6 lstRecipients +=
> lst.options[i].value;
> 7 lstRecipients += ",";
> 8 //alert(i);
> 9 //alert(lstRecipients);
> 10 //}
> 11 }
> 12 return lstRecipients;
> 13 }
>



 
Reply With Quote
 
Curt_C [MVP]
Guest
Posts: n/a
 
      01-13-2004
after the loop, trim off the last character.....

--
Curt Christianson
Owner/Lead Developer, DF-Software
www.Darkfalz.com


"Scott" <(E-Mail Removed)> wrote in message
news:033501c3da0e$54fb79b0$(E-Mail Removed)...
> 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[i].selected){
> 6 lstRecipients +=
> lst.options[i].value;
> 7 lstRecipients += ",";
> 8 //alert(i);
> 9 //alert(lstRecipients);
> 10 //}
> 11 }
> 12 return lstRecipients;
> 13 }
>



 
Reply With Quote
 
Harag
Guest
Posts: n/a
 
      01-14-2004

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


On Tue, 13 Jan 2004 15:05:10 -0500, "Ray at <%=sLocation%>"
<myfirstname at lane34 dot com> wrote:

>This isn't the right group for javascript issues. .scripting.jscript is a
>decent one for such questions.
>
>Ray at work
>
>"Scott" <(E-Mail Removed)> wrote in message
>news:033501c3da0e$54fb79b0$(E-Mail Removed)...
>> 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[i].selected){
>> 6 lstRecipients +=
>> lst.options[i].value;
>> 7 lstRecipients += ",";
>> 8 //alert(i);
>> 9 //alert(lstRecipients);
>> 10 //}
>> 11 }
>> 12 return lstRecipients;
>> 13 }
>>

>


 
Reply With Quote
 
Harag
Guest
Posts: n/a
 
      01-14-2004

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

Al.


On Tue, 13 Jan 2004 15:05:10 -0500, "Ray at <%=sLocation%>"
<myfirstname at lane34 dot com> wrote:

>This isn't the right group for javascript issues. .scripting.jscript is a
>decent one for such questions.
>
>Ray at work
>
>"Scott" <(E-Mail Removed)> wrote in message
>news:033501c3da0e$54fb79b0$(E-Mail Removed)...
>> 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[i].selected){
>> 6 lstRecipients +=
>> lst.options[i].value;
>> 7 lstRecipients += ",";
>> 8 //alert(i);
>> 9 //alert(lstRecipients);
>> 10 //}
>> 11 }
>> 12 return lstRecipients;
>> 13 }
>>

>


 
Reply With Quote
 
Ray at
Guest
Posts: n/a
 
      01-14-2004
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> oops, just noticed he's using client side code, so yes the other group
> will be better as ASP is a serverside group.
>
> Al.
>



 
Reply With Quote
 
Harag
Guest
Posts: n/a
 
      01-14-2004

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.


On Tue, 13 Jan 2004 20:54:08 -0500, "Ray at <%=sLocation%>"
<myFirstNameATlane34dotKOMM> wrote:

>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" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>>
>> oops, just noticed he's using client side code, so yes the other group
>> will be better as ASP is a serverside group.
>>
>> Al.
>>

>


 
Reply With Quote
 
Dave Anderson
Guest
Posts: n/a
 
      01-14-2004
"Ray at <%=sLocation%>" wrote:
>
> 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.


 
Reply With Quote
 
Guest
Posts: n/a
 
      01-16-2004
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.

>-----Original Message-----
>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[i].selected){
>6 lstRecipients +=
>lst.options[i].value;
>7 lstRecipients += ",";
>8 //alert(i);
>9 //alert(lstRecipients);
>10 //}
>11 }
>12 return lstRecipients;
>13 }
>
>.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Question about question mark in JavaScript Jimolo Javascript 2 01-20-2008 05:02 PM
Generated JavaScript vs. Manually Created JavaScript: Which one comes first? Nathan Sokalski ASP .Net 4 11-08-2007 07:24 AM
JavaScript or not JavaScript Mark Rae ASP .Net 36 09-09-2006 01:12 PM
href="javascript:func()" vs href="#" onclick="javascript:func()" CRON HTML 24 06-20-2006 08:05 PM
Javascript -> Applet: variable reset after method call from javascript?! mcdeveloper Java 1 06-13-2006 08:34 AM



Advertisments