Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    ASP Loop within JS???

    I wonder if I can use ASP loop within JS. I am trying to do a cross-browser text scroller that reads the data from the database where I would like to get all the datas and scroll them but the way I did of course it just reads the the first data with the id number 1 so i thought if i could use 'do while not EOF' loop within javasript it will be sorted out.

    At the moment I am using within javascript to get the data

    var marqueecontent='<%=oRS("Content")%>'

    which gives me the Content of the news with id=1 where I would like it to scroll all the contents. I wouldn't know how many news ids there will be as this will be decided by the admin of the site.

    any ideas?

  • #2
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I can't explain this at the moment... but you cannot access the server using javascript client-side.

    In order to get new information from the server, either the page has to be refreshed, or you have to make a remote server call... this can't be done with javascript.

    JavaScript = Executed on the user's computer (doesn't know what has changed on the server! It's on the user's computer!)
    ASP = Executed on the server, and sent to the user's computer AS HTML or JavaScript (all client-side stuff is returned FROM the server) - in order to get this information, you have to query the server again.
    Last edited by whammy; 02-28-2003 at 01:23 AM.
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #3
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    <script language="javascript">
    var marqueecontent = new Array();
    <%
    while not oRS.EOF
    %>
    marqueecontent[marqueecontent.length]='<%=oRS("Content")%>';
    <%
    oRS.movenext
    wend
    %>
    </script>

    sample output would be:

    var marqueecontent = new Array();
    marqueecontent[marqueecontent.length]='marquee1';
    marqueecontent[marqueecontent.length]='marquee2';
    marqueecontent[marqueecontent.length]='marquee3';


    you now have an array of marquees.
    you can access each by specifying the index.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for explaining that better than I can, Glenn!
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #5
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Cheers guy it just worked fine now I can display the news tittle and the content with the code:

    %>
    marqueecontent[marqueecontent.length]='<%=oRS("Tittle")& "<br>"

    %><%=oRS("Content")& "<p>"%>

    But somehow it puts "," before each news title any idea of what this happens.

    Plus

    I would like to make the news tittles hyperlink so once the user clicks they can go to other relevant pages to get more info. I already have an URL attribute in my table in database I just need to code how ASP does this hyperlinking stuff.

    Thanks

  • #6
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Or... how about:

    mc[mc.length][0]='<%=oRS("Tittle")%>'
    mc[mc.length][1]='<%=oRS("Content")%>'
    mc[mc.length][2]='<%=oRS("URL")%>'


    and then.....

    for(i=0;i<mc.length;i++){
    document.write(mc[i][0]+"<br>"+mc[i][1]+"<a href='"+mc[i][2]+"'>link</a>")
    }



    Mmmmmmm, multidimensional arrays...

  • #7
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    var marqueecontent=new Array();
    <%
    while not oRS.EOF

    marqueecontent[marqueecontent.length][0]='<%=oRS("Tittle")%>'
    marqueecontent[marqueecontent.length][1]='<%=oRS("Content")%>'
    marqueecontent[marqueecontent.length][2]='<%=oRS("URL")%>'


    for(i=0;i<marqueecontent.length;i++){
    document.write([marqueecontenti][0]+"<br>"+marqueecontent[i][1]+"<a href='"+marqueecontent[i][2]+"'>link</a>")
    }
    %>
    <%
    oRS.movenext
    wend
    %>


    I have used this code below and it keeps giving the error of :

    Microsoft VBScript compilation error '800a0401'

    Expected end of statement

    /anticus/s.asp, line 50

    marqueecontent[marqueecontent.length][0]='<%=oRS("Tittle")
    -----------------------------------------------------^

    I couldn't figure out where the problem is.

    Any suggestions?

  • #8
    Senior Coder
    Join Date
    Jun 2002
    Location
    41° 8' 52" N -95° 53' 31" W
    Posts
    3,660
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yeah, you never have a closing ASP tag before you try to write to javascript, like:

    %>

    i.e.:

    var marqueecontent=new Array();
    <%
    while not oRS.EOF
    %>
    marqueecontent[marqueecontent.length][0]='<%=oRS("Tittle")%>'
    marqueecontent[marqueecontent.length][1]='<%=oRS("Content")%>'
    marqueecontent[marqueecontent.length][2]='<%=oRS("URL")%>'
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

  • #9
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    and the javascript for loop should be outside the vbscript while loop. Plus you have other errors like not declaring an item to be an array to make a 2d array and this:

    document.write([marqueecontenti][0]+...

    here's the correct code:

    var marqueecontent=new Array();
    <%
    while not oRS.EOF
    %>
    index = marqueecontent.length;
    marqueecontent[index] = new Array();
    marqueecontent[index][0]='<%=oRS("Tittle")%>'
    marqueecontent[index][1]='<%=oRS("Content")%>'
    marqueecontent[index][2]='<%=oRS("URL")%>'
    <%
    oRS.movenext
    wend
    %>
    for(i=0;i<marqueecontent.length;i++){
    document.write(marqueecontent[i][0]+"<br>"+marqueecontent[i][1]+"<a href='"+marqueecontent[i][2]+"'>link</a>")
    }
    Last edited by glenngv; 03-03-2003 at 12:09 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #10
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanx for your help guys,

    the thing is this javascript i am working on is for scrolling text so i don't really want it to display the information in response.write format it is enough to attend them to arrays as the js reads the array and display it...

    i wonder if i can add the url to the title so it will write the name of event but it will appear in blur as it will be hyperlink. so what i would like now is to attend the url address in the database to the tittle so that when a user clicks on the title they will go to the relevant page.

    var marqueecontent=new Array();
    <%
    while not oRS.EOF
    %>
    index = marqueecontent.length;
    marqueecontent[index] = new Array();
    marqueecontent[index][0]='<%=oRS("Tittle")& "<br>"%>'
    marqueecontent[index][1]='<%=oRS("Content")%>'

    <%
    oRS.movenext
    wend
    %>


    i am using the code above now what i need is to add the code
    '<%=oRS("URL")%>' next to marqueecontent[index][0]='<%=oRS("Tittle")& "<br>"%>'

    does anyone have an idea of how to make this tittle a hyperlink which gets the url address from the database?

    Thanks

  • #11
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    You mean:

    Code:
    var marqueecontent=new Array(); 
    <% 
    while not oRS.EOF 
    %> 
    index = marqueecontent.length; 
    marqueecontent[index] = new Array(); 
    marqueecontent[index][0]='<a href="<%=oRS("URL")%>"><%=oRS("Tittle")%></a>' 
    marqueecontent[index][1]='<%=oRS("Content")%>' 
    
    <% 
    oRS.movenext 
    wend 
    %>

    ??

  • #12
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yup that's it...thanx very much the only problem now is when I try to use :

    marqueecontent[index][1]='<%=oRS("Content")& "<br>" %>'

    This <br> tag to make it look neater it puts "," before and after the news tittle when I view it, is there any way of getting rid of it?

    without the <br> it looks nice but i need it as i wanna seperate each tittle and its content from the other news...

    Thanks

  • #13
    Senior Coder Spudhead's Avatar
    Join Date
    Jun 2002
    Location
    London, UK
    Posts
    1,856
    Thanks
    8
    Thanked 110 Times in 109 Posts
    Random commas? Dunno where they're coming from, are you sure they're not in your data? Try:

    marqueecontent[index][1]='<%=oRS("Content")%><br>'

  • #14
    Regular Coder
    Join Date
    Jan 2003
    Posts
    148
    Thanks
    0
    Thanked 0 Times in 0 Posts
    umm i have tried that it still put comas for some reason.I have checked the js code but didn't see anything where it puts comma when u go to next line...strange but nevermind

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •