javaScript question

Discussion in 'ASP General' started by Scott, Jan 13, 2004.

  1. Scott

    Scott Guest

    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 }
     
    Scott, Jan 13, 2004
    #1
    1. Advertising

  2. 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" <> escreveu na mensagem
    news:033501c3da0e$54fb79b0$...
    > 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 }
    >
     
    Vilmar Brazão de Oliveira, Jan 13, 2004
    #2
    1. Advertising

  3. Scott

    Ray at Guest

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

    Ray at work

    "Scott" <> wrote in message
    news:033501c3da0e$54fb79b0$...
    > 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 }
    >
     
    Ray at, Jan 13, 2004
    #3
  4. Scott

    Curt_C [MVP] Guest

    after the loop, trim off the last character.....

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


    "Scott" <> wrote in message
    news:033501c3da0e$54fb79b0$...
    > 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 }
    >
     
    Curt_C [MVP], Jan 13, 2004
    #4
  5. Scott

    Harag Guest

    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" <> wrote in message
    >news:033501c3da0e$54fb79b0$...
    >> 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 }
    >>

    >
     
    Harag, Jan 14, 2004
    #5
  6. Scott

    Harag Guest

    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" <> wrote in message
    >news:033501c3da0e$54fb79b0$...
    >> 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 }
    >>

    >
     
    Harag, Jan 14, 2004
    #6
  7. Scott

    Ray at Guest

    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" <> wrote in message
    news:...
    >
    > oops, just noticed he's using client side code, so yes the other group
    > will be better as ASP is a serverside group.
    >
    > Al.
    >
     
    Ray at, Jan 14, 2004
    #7
  8. Scott

    Harag Guest

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

    >
     
    Harag, Jan 14, 2004
    #8
  9. "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.
     
    Dave Anderson, Jan 14, 2004
    #9
  10. Scott

    Guest 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.

    >-----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.selected){
    >6 lstRecipients +=
    >lst.options.value;
    >7 lstRecipients += ",";
    >8 //alert(i);
    >9 //alert(lstRecipients);
    >10 //}
    >11 }
    >12 return lstRecipients;
    >13 }
    >
    >.
    >
     
    Guest, Jan 16, 2004
    #10
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. mcdeveloper
    Replies:
    1
    Views:
    4,279
    mcdeveloper
    Jun 13, 2006
  2. CRON
    Replies:
    24
    Views:
    203,880
    Adrienne Boswell
    Jun 20, 2006
  3. Mark Rae

    JavaScript or not JavaScript

    Mark Rae, Sep 5, 2006, in forum: ASP .Net
    Replies:
    36
    Views:
    1,134
    Paul Sture
    Sep 9, 2006
  4. Nathan Sokalski
    Replies:
    4
    Views:
    625
    PJ on Development
    Nov 8, 2007
  5. Jimolo
    Replies:
    2
    Views:
    239
    Gregor Kofler
    Jan 20, 2008
Loading...

Share This Page