Quote:
Originally Posted by Old Pedant
So how come your original posted code doesn't work???
Let's look at it again. With minor corrections/adaptations.
Code:
<script type="text/javascript">
function banner( image, number, url )
{
... this is the constructor for a banner ...
}
var pic = new Array( );
<%
Set conn = server.createobject("adodb.connection")
conn.open "DSN=XXXX" ' If possible, AVOID using DSN's for connections!!!
sql="Select bannerImage, bannerNumber, bannerURL from table"
Set rs = conn.Execute( sql )
counter = 0;
Do Until rs.EOF
image = rs("bannerImage")
num = rs("bannerNumber")
url = rs("bannerURL")
%>
pic[<%=counter%>] = new banner("<%=image%>","<%=num%>","<%=url%>");
<%
counter = counter + 1
rs.MoveNext
Loop
rs.close
%>
Now, there *IS* a slightly more elegant way to do this, which is also a little faster, but it's harder to follow.
Code:
<script type="text/javascript">
function banner( image, number, url )
{
... this is the constructor for a banner ...
}
<%
Set conn = server.createobject("adodb.connection")
conn.open "DSN=XXXX" ' If possible, AVOID using DSN's for connections!!!
sql="Select bannerImage, bannerNumber, bannerURL from table"
Set rs = conn.Execute( sql )
prefix = "new banner("""
midfix = ""","""
suffix1 = """)"
suffix2 = "," & vbNewLine
jsData = rs.getString( , , midfix, suffix1 & suffix2 & prefix )
jsData = prefix & Left( jsData, Len(jsData) - Len(suffix2) - Len(prefix) )
rs.Close
%>
var pic = new Array(
<%=jsData%>
);
Here's an old FAQ I wrote that explains the above.
|
Hi Old Pedant,
Sorry for my late response, we had a holidayweek here.
Why my code didn´t work, I don´t know. But I used the first part which you posted and made some little modification, and it works perfectly.
This is the code:
Code:
<Script type="text/javascript">
function banner(name, width, link){
this.name = name
this.width = width
this.link = link
}
var pic = new Array();
<%
Set conn = server.createobject("adodb.connection")
conn.open "DSN=FARMA"
set rs = server.createobject("adodb.recordset")
sql="Select * from informe_oferta"
rs.open sql,conn
counter=0
DO WHILE NOT rs.EOF
%>
pic[<%=counter%>] = new banner('<%=response.write(rs("foto"))%>',102,'<%=response.write(rs("url"))%>');
<%
counter=counter+1
rs.Movenext
LOOP
rs.close
%>
And it works now perfectly. may becauase my original had
instead of
Code:
<Script type="text/javascript">
As I am very new to Javascript/VBscript, I can´t tell. But anyway, I have learned a lot with your help (like using ";" in Javascripts)
Again Old Pedant, thx again..... And next time I will vote for you again as best helper!!!
regards