...

View Full Version : ASP Loop within JS???



pinkcat_02
02-27-2003, 07:43 PM
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?

whammy
02-28-2003, 02:20 AM
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.

glenngv
02-28-2003, 02:59 AM
<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.

whammy
02-28-2003, 03:06 AM
Thanks for explaining that better than I can, Glenn!

pinkcat_02
02-28-2003, 01:24 PM
:thumbsup: 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

Spudhead
02-28-2003, 04:45 PM
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... :thumbsup:

pinkcat_02
03-01-2003, 09:20 PM
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?

whammy
03-02-2003, 05:57 AM
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")%>'

glenngv
03-03-2003, 01:07 AM
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>")
}

pinkcat_02
03-04-2003, 04:02 PM
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

Spudhead
03-04-2003, 05:59 PM
You mean:



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
%>



??

pinkcat_02
03-04-2003, 06:34 PM
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

Spudhead
03-04-2003, 06:43 PM
Random commas? Dunno where they're coming from, are you sure they're not in your data? Try:

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

pinkcat_02
03-04-2003, 10:06 PM
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 :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum