...

View Full Version : ASP Text Scroller



JoeP
02-13-2003, 06:12 PM
I have received many great tips from this site, so I thought I might share this one. It may be simple to experienced programmers, but it sure help me.

I was looking a vertical text scroller on the web and there were many. Most were DTHML/Javascript/Applets. I tinkered around and came up with this as a very effective and neat script to put in a table cell well you want to list values out of an SQL database.

I wanted to list Members / Usernames from an MS Access 2000 DB scrolling vertrical. This does the trick just fine and very efficiently. All variables can be defined etc. to your liking.

Of course, ways to improve it are more than welcome!



<%
'==================================================================================
'Open Database And Get Names
Response.write("<Marquee align='center' width='100' height='20' onmouseover='this.stop();' onmouseout='this.start();' direction='up' scrollamount='1' scrolldelay='60' top='0' left='15' style='font-family: Arial Narrow; font-size: 8pt'>" )
Set conn = server.createobject("adodb.connection")
dbName="MyDatabase.mdb"
connect ="provider=microsoft.jet.oledb.4.0;data source="
connect=connect & server.mappath(dbName)& ";"
conn.open connect
SQLstmt = "SELECT * FROM [Member]"
set rs = conn.Execute(SQLstmt)
if not rs.EOF then
rs.movefirst
Do
UserName = UCase(rs("UserName"))
UserName = UserName & "<br>"
Response.write(UserName)
rs.movenext
loop until rs.EOF
End If
'==================================================================================
'Clean Up And Close Database
Set rs = Nothing
Set connect = Nothing
Set SQLstmt = Nothing
conn.close
Set conn = Nothing
Set dbName = Nothing
Response.write( "</Marquee>" )
'==================================================================================
%>

pinkcat_02
02-14-2003, 01:14 AM
Great, I was just trying to combine javascript with ASP to implement a scroll text. This code helped a lot, I will try to modify it such as giving links and trying different colours for news topic and another colour for the content, hopw it works :)

Thanks again great help:thumbsup:

whammy
02-14-2003, 01:43 AM
This is not cross-browser, however... if you're looking for a cross-browser implementation, I would avoid the <marquee> tag.

pinkcat_02
02-14-2003, 01:45 AM
is it only the marquee tag that avoids it from being cross browser then?

whammy
02-14-2003, 01:51 AM
The marquee tag is a VERY VERY bad thing.

The reason I say that, is <marquee> is a proprietary tag introduced by Microsoft, that only works in their browsers. I'm not even sure it still works in their newest browsers.

I would have to check to verify that, but to be honest with you, I see something like that as a waste of my time, since I personally avoid proprietary code as much as possible and try to stick to ECMA and W3 standards.

You're much better off using another method to do whatever it is you're attempting, but I'm sure if you post your question in the "General Web building" forum in its own thread, you might get better answers, since this doesn't have much to do with ASP.

:)

pinkcat_02
02-14-2003, 01:54 AM
Yeah I have just read about marquee :(
umm I better carry on what I was doing then cos as everyone does, I would like to have a cross-browser site.

Thanx 4 warning :)

whammy
02-14-2003, 01:59 AM
You bet. :)

JoeP
02-14-2003, 02:40 AM
Yep, This is what I was afraid of after I posted this. But Man, this little script works nice for what I have. Unfortunately, It will probably blow Netscape and all those type browsers out of the water.

The reason I like it, and the reason I use ASP is to obviously build the text string for all the members.

Oh well, another lesson learned here, and I hope I didn't cause any problems.

Thx for the insight, Whammy...

JoeP

whammy
02-14-2003, 02:45 AM
On the contrary... if you find out this works in other browsers, please let us know! I doubt that though. You definitely didn't cause any problems... all posts and ideas are welcomed here, and I am most definitely not correct all of the time. I learn a lot from this forum!

However, stuff like this is just "flashy" anyway, and IMHO it doesn't really serve a utlitarian purpose, so it likely won't affect anyone who isn't trying to be "flashy".

What you can do though, is check to see if the client's browser supports your script by using other techniques to determine the browser type (see the javascript forum), and then, if it's supported, work your magic.

:)

pinkcat_02
02-14-2003, 06:02 PM
i was adviced that the marquee sript on this iste is cross browser one, I haven't tested it myself thoug. will try at the weekend.



http://www.dynamicdrive.com/dynamicindex2/cmarquee.htm

pinkcat_02
02-17-2003, 10:11 PM
I have checked the code and I had seen that was a javascript, however I wonder if I can still call the data from the database with Response.Write action within javascript. If not what can be the alternative way?


It is something like:

<script language="JavaScript1.2">

//Specify the marquee's width (in pixels)
var marqueewidth=300
//Specify the marquee's height
var marqueeheight=25
//Specify the marquee's marquee speed (larger is faster 1-10)
var marqueespeed=3
//configure background color:
var marqueebgcolor="#DEFDD9"
//Pause marquee onMousever (0=no. 1=yes)?
var pauseit=1

//Specify the marquee's content (don't delete <nobr> tag)
//Keep all content on ONE line, and backslash any single quotations (ie: that\'s great):

var marqueecontent='<nobr><%

Response.write("<font-family: Arial Narrow; font-size: 8pt>" )
Set conn = server.createobject("adodb.connection")
dbName="deneme.mdb"
connect ="provider=microsoft.jet.oledb.4.0;data source="
connect=connect & server.mappath(dbName)& ";"
conn.open connect

SQLstmt = "SELECT * FROM [Branch]"
set rs = conn.Execute(SQLstmt)
if not rs.EOF then
rs.movefirst
Do
Branch_Code = (rs("Branch_Code"))
Branch_Code = Branch_Code & "<br>"
Response.write(Branch_Code)
rs.movenext
loop until rs.EOF
End If

'Clean Up And Close Database
Set rs = Nothing

Set SQLstmt = Nothing
conn.close
Set conn = Nothing

Respinse.Write("Hi")
%>
</nobr>'



marqueespeed=(document.all)? marqueespeed : Math.max(1, marqueespeed-1) //slow speed down by 1 for NS
var copyspeed=marqueespeed
var pausespeed=(pauseit==0)? copyspeed: 0
var iedom=document.all||document.getElementById
if (iedom)
document.write('<span id="temp" style="visibility:hidden;position:absolute;top:-100;left:-5000">'+marqueecontent+'</span>')
var actualwidth=''
var cross_marquee, ns_marquee

function populate(){
if (iedom){
cross_marquee=document.getElementById? document.getElementById("iemarquee") : document.all.iemarquee
cross_marquee.style.left=marqueewidth+8
cross_marquee.innerHTML=marqueecontent
actualwidth=document.all? cross_marquee.offsetWidth : document.getElementById("temp").offsetWidth
}
else if (document.layers){
ns_marquee=document.ns_marquee.document.ns_marquee2
ns_marquee.left=marqueewidth+8
ns_marquee.document.write(marqueecontent)
ns_marquee.document.close()
actualwidth=ns_marquee.document.width
}
lefttime=setInterval("scrollmarquee()",20)
}
window.onload=populate

function scrollmarquee(){
if (iedom){
if (parseInt(cross_marquee.style.left)>(actualwidth*(-1)+8))
cross_marquee.style.left=parseInt(cross_marquee.style.left)-copyspeed
else
cross_marquee.style.left=marqueewidth+8

}
else if (document.layers){
if (ns_marquee.left>(actualwidth*(-1)+8))
ns_marquee.left-=copyspeed
else
ns_marquee.left=marqueewidth+8
}
}

if (iedom||document.layers){
with (document){
document.write('<table border="0" cellspacing="0" cellpadding="0"><td>')
if (iedom){
write('<div style="position:relative;width:'+marqueewidth+';height:'+marqueeheight+';overflow:hidden">')
write('<div style="position:absolute;width:'+marqueewidth+';height:'+marqueeheight+';background-color:'+marqueebgcolor+'" onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed">')
write('<div id="iemarquee" style="position:absolute;left:0;top:0"></div>')
write('</div></div>')
}
else if (document.layers){
write('<ilayer width='+marqueewidth+' height='+marqueeheight+' name="ns_marquee" bgColor='+marqueebgcolor+'>')
write('<layer name="ns_marquee2" left=0 top=0 onMouseover="copyspeed=pausespeed" onMouseout="copyspeed=marqueespeed"></layer>')
write('</ilayer>')
}
document.write('</td></table>')
}
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum