...

View Full Version : Error displaying message in an array



pthompson2002
08-21-2002, 02:14 PM
Hopefully someone can help.

I have a scrollbar/slider on my page that scrolls through "titles" from an array. The array is populated from a database. When the user clicks on one of the "titles" the message that accompanies it is displayed in <div> underneath the scroller. This works fine except for when you try and click on the title for the last element in the array, it does not display.

CODE------

document.writeln('<font color=orange><div id="ieslider1" onclick="showMsg((i-1)) style="position:relative;width:'+swidth+'; cursor: hand;">')

---------------

the above code shows the onclick event which selects the message to be shown. It is (i-1) as the 1st title is the zero element in the array. For example, the 1st title to be clicked on will want the 0th message displayed. The showMsg function is:

function showMsg(whichMsg){

// Pump in the message text
var headerDiv = messages[whichMsg][0]
var displayDiv = messages[whichMsg][1]
msgDiv.innerHTML = '<h3>'+ headerDiv +'</h3>'+ displayDiv
}

I have tried everything I know to get this to work and everytime it fails for the final element.

Any ideas?

beetle
08-21-2002, 02:42 PM
Do you have your code online someplace? Nothing pops right out at me that looks like an error.

On a side note, I'd ditch that FONT tag, especially since you already have style rules applied to that DIV, and make sure to add one the missing double quote...

document.writeln('<div id="ieslider1" onclick="showMsg((i-1))" style="color:orange; position:relative;width:'+swidth+'; cursor: hand;">')

pthompson2002
08-21-2002, 03:28 PM
I'm afraid not, the best I can do is paste all ym code. Obviously :

<%@ Language=VBScript %>
<%
Dim cn ' Connection
Dim rsBroadcast ' Table Broadcast Recordset
Dim SQLBroadcast ' Broadcast SQL Query
Dim iStat ' Value for the default selected item
Dim i ' Length of Array
Dim j ' Used to iterate through the arrays

'Define the queries
SQLBroadcast = "SELECT Title, Message FROM Broadcast"

'Define the Connection and Recordset Objects
Set cn = server.CreateObject("ADODB.Connection")
set rsBroadcast = server.CreateObject("ADODB.Recordset")
set rsCount = server.CreateObject("ADODB.Recordset")

cn.Open "DSN=******"

'Open the Recordsets using the open connection
rsBroadcast.Open SQLBroadcast, cn

'Make sure Recordset is at the first record
rsBroadcast.MoveFirst
%>
<HTML>
<HEAD>
<Style type="text/css">
<!-- format and size the DIV tag -->
.myDivStyle {
position:absolute;
width:500px; height:200px;
}
</Style>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<SCRIPT LANGUAGE="JavaScript">
<!-- //Begin Hide
//slider's width
var swidth=500

//slider's height
var sheight=72

//slider's speed
var sspeed=2

//Create the Array
var messages = new Array();

//Populate the Array
<%
i = 0
do while NOT rsBroadcast.EOF
%>
messages[<%=i%>]= new Array("<%=rsBroadcast("Title")%>","<%=rsBroadcast("Message")%>")
<%
i = i + 1
rsBroadcast.MoveNext
Loop
%>

// On click show message for title in div
function showMsg(whichMsg){
alert(whichMsg)
// Pump in the message text
var headerDiv = messages[whichMsg][0]
var displayDiv = messages[whichMsg][1]
msgDiv.innerHTML = '<h3>'+ headerDiv +'</h3>'+ displayDiv
}

//------------------Functionality for Scroller/Slider---------------------//

if (messages.length>1)
i=0

function start(){
if (document.all){
ieslider1.style.top=sheight
iemarquee(ieslider1)
}
else if (document.layers){
document.ns4slider.document.ns4slider1.top=sheight
document.ns4slider.document.ns4slider1.visibility='show'
ns4marquee(document.ns4slider.document.ns4slider1)
}
else if (document.getElementById&&!document.all){
document.getElementById('ns6slider1').style.top=sheight
ns6marquee(document.getElementById('ns6slider1'))
}
}

function iemarquee(whichdiv){
iediv=eval(whichdiv)
if (iediv.style.pixelTop>0&&iediv.style.pixelTop<=sspeed){
iediv.style.pixelTop=0
setTimeout("iemarquee(iediv)",100)
}
if (iediv.style.pixelTop>=sheight*-1){
iediv.style.pixelTop-=sspeed
setTimeout("iemarquee(iediv)",100)
}
else {
iediv.style.pixelTop=sheight
iediv.innerHTML=messages[i][0]
if (i==messages.length-1)
i=1
else
i++
}
}

function ns4marquee(whichlayer){
ns4layer=eval(whichlayer)
if (ns4layer.top>0&&ns4layer.top<=sspeed){
ns4layer.top=0
setTimeout("ns4marquee(ns4layer)",100)
}

if (ns4layer.top>=sheight*-1){
ns4layer.top-=sspeed
setTimeout("ns4marquee(ns4layer)",100)
}

else {
ns4layer.top=sheight
ns4layer.document.write(messages[i][0])
ns4layer.document.close()
if (i==messages.length-1)
i=0
else
i++
}
}

function ns6marquee(whichdiv){
ns6div=eval(whichdiv)
if (parseInt(ns6div.style.top)>0&&parseInt(ns6div.style.top)<=sspeed){
ns6div.style.top=0
setTimeout("ns6marquee(ns6div)",100)
}

if (parseInt(ns6div.style.top)>=sheight*-1){
ns6div.style.top=parseInt(ns6div.style.top)-sspeed
setTimeout("ns6marquee(ns6div)",100)
}
else {
ns6div.style.top=sheight
ns6div.innerHTML=messages[i][0]

if (i==messages.length-1)
i=0
else
i++
}
}
// End Hide -->
</SCRIPT>
</HEAD>
<BODY onLoad="start()">
<span style="borderWidth:1; borderColor:red; width:350; height:72; background:navy">
<ilayer id="ns4slider" width="&{swidth};" height="&{sheight};">
<layer id="ns4slider1" height="&{sheight};" onmouseover="sspeed=0;" onmouseout="sspeed=2">
<script language="JavaScript">
if (document.layers)//If NS4
document.write(messages[i][0])
</script>
</layer></ilayer>
<script language="JavaScript">
if (document.all){//If IE
document.write('<table width=500 border=0><tr><td bgcolor=red><font color=white><center>BCMC Broadcast Message</center></font></td></tr></table>');
document.writeln('<div style="position:relative;overflow:hidden;width:'+swidth+';height:'+sheight+';clip:rect(0 '+swidth+' '+sheight+' 0);border:1 solid red;" onmouseover="sspeed=0;" onmouseout="sspeed=2">')
document.writeln('<font color=orange><div id="ieslider1" onclick="showMsg(i)" style="position:relative;width:'+swidth+'; cursor: hand;">')
document.write(messages[i][0])
document.writeln('</div></font></div>')
document.write('<div id="msgDiv" class="myDivStyle"></div>');
}
if(document.getElementById&&!document.all){//If NS6
document.writeln('<div style="position:relative;overflow:hidden;width:'+swidth+';height:'+sheight+';clip:rect(0 '+swidth+' '+sheight+' 0);border:1px solid red;" onmouseover="sspeed=0;" onmouseout="sspeed=2">')
document.writeln('<font color=orange><div id="ns6slider1" onclick="showMsg([i])" style="position:relative;width:'+swidth+'; cursor: hand;">')
document.write(messages[i][0])
document.writeln('</div></font></div>')
}
</script>
<%
rsBroadcast.Close
set rsBroadcast = Nothing
cn.Close
set cn = Nothing
%>
</span>
</div>
</BODY>
</HTML>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum