Click to See Complete Forum and Search --> : calling data from ASP to javascript


nesh
04-03-2005, 04:11 AM
anyone please help me ..


how to get data (i_title, i_summary, go_high) from high_view.asp to fcontent array(javascript)...


/ high_view.asp
<%
'high_view.asp
sub disp_main_query ( h_title, h_summary, go_high)
dim sql

sql= "select * from highlight"

if not runSQLdbEC(sql) then response.End
if not rsdbEC.EOF then

ds=rsdbEC.GetRows
cntRec=ubound(ds,2)+1

'printf "cntRec=" & cntRec & "<BR>"
redim arrh_id(cntRec),arrh_title(cntRec),arrh_summary(cntRec),arrgo_high(cntRec)
for ctrArr=0 to cntRec-1
arrh_id(ctrArr)=ds(0,ctrArr)
arrh_title(ctrArr) = ds(1,ctrArr)
arrh_summary(ctrArr) = ds(2,ctrArr)
arrgo_high(ctrArr) = ds(3,ctrArr)
next

set rsdbEc=nothing
'printf"<br><br><br><br>"
printf "<table width=70% border=1 align=center cellpadding=1 cellspacing=0> "
printf "<tr bgcolor=6699FF><td width=20% height=21><div align=center><font size=1 face=Verdana><strong>Title</strong></font></div></td>"
printf "<td width=35% ><div align=center><font size=1 face=Verdana><strong>Summary</strong></font></div></td>"
printf "<td width=20% ><div align=center><font size=1><strong><font face=Verdana>Hyperlink</font></strong></font></div></td>"
printf "<td width=15% ><div align=center><font size=1><strong><font face=Verdana>Edit</font></strong></font></div></td>"
printf "<td width=15% ><div align=center><font size=1><strong><font face=Verdana>Delete</font></strong></font></div></td></tr>"


for ctrArr=0 to cntRec-1
temp = "?h_id=" & server.urlencode(arrh_id(ctrArr)) & "&h_title=" & server.urlencode(arrh_title(ctrArr))
temp = temp & "&h_summary=" & server.urlencode(arrh_summary(ctrArr)) & "&go_high=" & server.urlencode(arrgo_high(ctrArr))


printf "<table width=70% border=1 align=center cellpadding=1 cellspacing=0> "
printf "<Tr><td width=20% align=center><font size=1 face=Verdana>" & arrh_title(ctrArr) & "</td>"
printf "<td width=35% align=center><font size=1 face=Verdana>" & arrh_summary(ctrArr) & "</Td>"
printf "<td width=20% align=center><font size=1 face=Verdana>" & arrgo_high(ctrArr) & "</Tr>"
printf "<td width=15% align=center><font size=1 face=Verdana><A href=""high_edit.asp" & temp & """>Edit</Tr>"
printf "<td width=15% align=center><font size=1 face=Verdana><A href=""high_delete.asp" & temp & """>Delete</TD></tr></table>"

printf"</table>"

next
end if
end sub
%>

______________________________________

<script type="text/javascript">


var delay = 2000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

var fcontent=new Array();
begintag='<div style="font: normal Arial; border=0px: 5px;">'; //set opening tag, such as font declarations
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>";
closetag='</div>';


var fwidth='175px'; //set scroller width
var fheight='160px'; //set scroller height[/B]

var fadelinks=1; //should links inside scroller content also fade like text? 0 for no, 1 for yes.

var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;

//function to change content
function changecontent(){
if (index>=fcontent.length)
index=0
if (DOM2){
document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
if (fadelinks)
linkcolorchange(1);
colorfade(1, 15);
}
else if (ie4)
document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
index++
}



function linkcolorchange(step){
var obj=document.getElementById("fscroller").getElementsByTagName("A");
if (obj.length>0){
for (i=0;i<obj.length;i++)
obj[i].style.color=getstepcolor(step);
}
}


var fadecounter;
function colorfade(step) {
if(step<=maxsteps) {
document.getElementById("fscroller").style.color=getstepcolor(step);
if (fadelinks)
linkcolorchange(step);
step++;
fadecounter=setTimeout("colorfade("+step+")",stepdelay);
}else{
clearTimeout(fadecounter);
document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
setTimeout("changecontent()", delay);

}
}


function getstepcolor(step) {
var diff
var newcolor=new Array(3);
for(var i=0;i<3;i++) {
diff = (startcolor[i]-endcolor[i]);
if(diff > 0) {
newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
} else {
newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
}
}
return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

if (ie4||DOM2)
document.write('<div id="fscroller" style="border:1px solid black;width:'+fwidth+';height:'+fheight+'"></div>');

if (window.addEventListener)
window.addEventListener("load", changecontent, false)
else if (window.attachEvent)
window.attachEvent("onload", changecontent)
else if (document.getElementById)


</script>



please..please :confused:

<Eddie>
04-03-2005, 09:01 AM
Unless I'm completely off the point here, you generate the fcontent[] array values as you loop the recordset. You're passing a recordset to an array, then looping the array to generate the HTML. Loop the recordset only then build the JavaScript array and HTML as you do.

nesh
04-03-2005, 10:29 PM
Unless I'm completely off the point here, you generate the fcontent[] array values as you loop the recordset. You're passing a recordset to an array, then looping the array to generate the HTML. Loop the recordset only then build the JavaScript array and HTML as you do.


i think i'm the one who is :eek: can u please show me some example...
I try to do this..

var fcontent=<%=arrh_title(cntRec)%>,<%arrh_summary(cntRec)%>,<%arrgo_high(cntRec)%>;

is this valid or not..
one more thing...i try to put javascript into high_view.asp but seem it is not right.

<%
'high_view1.asp
sub disp_main_query ( h_title, h_summary, go_high)
dim sql
sql= "select * from highlight"
if not runSQLdbEC(sql) then response.End
if not rsdbEC.EOF then

ds=rsdbEC.GetRows
cntRec=ubound(ds,2)+1
'printf "cntRec=" & cntRec & "<BR>"

redim arrh_id(cntRec),arrh_title(cntRec),arrh_summary(cntRec),arrgo_high(cntRec)
for ctrArr=0 to cntRec-1
arrh_id(ctrArr)=ds(0,ctrArr)
arrh_title(ctrArr) = ds(1,ctrArr)
arrh_summary(ctrArr) = ds(2,ctrArr)
arrgo_high(ctrArr) = ds(3,ctrArr)
next

set rsdbEc=nothing

%>

//put javascript here
<script type="text/javascript">
var delay = 2000; //set delay between message change (in miliseconds)
var maxsteps=30; // number of steps to take to change from start color to endcolor
var stepdelay=40; // time in miliseconds of a single step
//**Note: maxsteps*stepdelay will be total time in miliseconds of fading effect
var startcolor= new Array(255,255,255); // start color (red, green, blue)
var endcolor=new Array(0,0,0); // end color (red, green, blue)

var fcontent=new Array();
begintag='<div style="font: normal Arial; border=0px: 5px;">'; //set opening tag, such as font declarations
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>";
closetag='</div>';

var fwidth='175px'; //set scroller width
var fheight='160px'; //set scroller height

var fadelinks=1; //should links inside scroller content also fade like text? 0 for no, 1 for yes.

///No need to edit below this line/////////////////
var ie4=document.all&&!document.getElementById;
var DOM2=document.getElementById;
var faderdelay=0;
var index=0;

//function to change content
function changecontent(){
if (index>=fcontent.length)
index=0
if (DOM2){
document.getElementById("fscroller").style.color="rgb("+startcolor[0]+", "+startcolor[1]+", "+startcolor[2]+")"
document.getElementById("fscroller").innerHTML=begintag+fcontent[index]+closetag
if (fadelinks)
linkcolorchange(1);
colorfade(1, 15);
}
else if (ie4)
document.all.fscroller.innerHTML=begintag+fcontent[index]+closetag;
index++
}

// colorfade() partially by Marcio Galli for Netscape Communications. ////////////
// Modified by Dynamicdrive.com

function linkcolorchange(step){
var obj=document.getElementById("fscroller").getElementsByTagName("A");
if (obj.length>0){
for (i=0;i<obj.length;i++)
obj[i].style.color=getstepcolor(step);
}
}
var fadecounter;
function colorfade(step) {
if(step<=maxsteps) {
document.getElementById("fscroller").style.color=getstepcolor(step);
if (fadelinks)
linkcolorchange(step);
step++;
fadecounter=setTimeout("colorfade("+step+")",stepdelay);
}else{
clearTimeout(fadecounter);
document.getElementById("fscroller").style.color="rgb("+endcolor[0]+", "+endcolor[1]+", "+endcolor[2]+")";
setTimeout("changecontent()", delay);
}
}

function getstepcolor(step) {
var diff
var newcolor=new Array(3);
for(var i=0;i<3;i++) {
diff = (startcolor[i]-endcolor[i]);
if(diff > 0) {
newcolor[i] = startcolor[i]-(Math.round((diff/maxsteps))*step);
} else {
newcolor[i] = startcolor[i]+(Math.round((Math.abs(diff)/maxsteps))*step);
}
}
return ("rgb(" + newcolor[0] + ", " + newcolor[1] + ", " + newcolor[2] + ")");
}

if (ie4||DOM2)
document.write('<div id="fscroller" style="border:1px solid black;width:'+fwidth+';height:'+fheight+'"></div>');

if (window.addEventListener)
window.addEventListener("load", changecontent, false)
else if (window.attachEvent)
window.attachEvent("onload", changecontent)
else if (document.getElementById)
window.onload=changecontent
</script>

<%

end if
end sub
%>