Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

inserting asp database value into javascript

Status
Not open for further replies.

shopwise

Technical User
Sep 22, 2008
52
US
I have the following javascript marquee code which uses static values:
Code:
fcontent[0]="<b>What\'s new?</b><br>New scripts added to the Scroller category!<br><br>The MoreZone has been updated. <a href='../morezone/index.htm'>Click here to visit</a>";
fcontent[1]="Dynamic Drive has been featured on Jars as a top 5% resource, and About.com as a recommended DHTML destination.";
fcontent[2]="Ok, enough with these pointless messages. You get the idea behind this script.</a>";

I would like to:
1. replace the static values with dynamic values
2. dynamically change the fcontent[0] number to increase with each repeated record.

With my limited coding knowledge I've tried the following to accomplish the above but it does not work:

Code:
<%
 Dim no
 no=0
While ((Repeat1__numRows <> 0) AND (NOT Recordset1.EOF)) 
%>
                                                   
fcontent[<%Response.Write(" &no&")%>]="<p><%= Recordset1("Company")%> - <%= Recordset1("City") %>, <%= Recordset1("State")%></br> 
                          </p>";
						  <% 
  no = no + 1
  
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  Recordset1.MoveNext()
Wend
%>

 
I don't know, but I think you are trying to make it too hard. This is untested but something like this ought to be a little closer:

Code:
...obtain your recordset (rs)...

<%
Dim no
no = 0 

If rs.Eof Then 
Response.write "<div align='center'>Some message.</div>" 
Else 

Do while not rs.Eof 

Response.Write "fcontent[" & no & "]=" & rs("Company") &
"- " & rs("City") & ", " & rs("State") & "</br></p>;"

no = no +1
rs.movenext

Loop 

End If

rs.Close
Set rs = Nothing 
%>

Someone who is better at escaping characters than I am will know if the ['s and ]'s if they need to be escaped and how to add the "'s and properly escape them if they are needed.

HTH.

 
I use one of dynamic drives scrollers to scroll activity on one page and menu items on another page. This is the asp page that I use for the activity info

Code:
<%

strQuery ="Select [activity] FROM qryactivity"

Dim objConn, dbPath, strProvider, rst
  dbPath = "C:\WEBSITES\physplantdb\PysPlant2002.mdb"%>
  <%Set objConn = Server.CreateObject("ADODB.Connection")
  strProvider = "PROVIDER=MICROSOFT.JET.OLEDB.4.0;DATA SOURCE=" & dbPath
    objConn.Open strProvider

Set rst = Server.CreateObject("ADODB.recordset")
rst.Open strQuery, strProvider,3,3%>

<%dim myArray
response.write "var pausecontent2=new Array();"
        i = 0
		     Do While Not rst.EOF
			   
			    myArray = myArray & "pausecontent2[" & i & "]='" & rst("activity") & "';"
		      i=i+1
			  rst.movenext
			  loop
response.write myArray %>
This array dynamically writes content that replaces this code in DD's scroller.
Code:
/*var pausecontent2=new Array()
pausecontent2[0]='Dining Hall Windows'
pausecontent2[1]='Childrens Ctr move'
pausecontent2[2]='Recycling Bins'
pausecontent2[3]='Ath Ctr Rooftop Unit Repair'
pausecontent2[4]='Scott Hall Steam Line'*/

Then instead of using the hard code above, I call the resulting array like this.

Code:
<script type="text/javascript" src=[ignore]"[URL unfurl="true"]http://physicalplant.williston.com/activityfile/activityasp.asp">[/URL][/ignore]

</script>

activityasp is the name of the file above. I know it's not exactly the same as what you are doing, but it might help spark some ideas for you.

Paul
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top