Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How would i get a "news".js file to populate its multidimensional array from a sql table?

Posted on 2006-04-11
4
Medium Priority
?
321 Views
Last Modified: 2008-02-01
Good morning experts,

I got this software that generates nice looking scrolling news scripts for me.  I want to be able to feed those scripts from a sql table where users can input information to it through a form.  I don't know if this could be done in .js files.

Can i include .asp or .cfm files in .js?

Here is one of the scripts that this software creates.

//news.js file

var titlea = new Array();var texta = new Array();var linka = new Array();var trgfrma = new Array();var heightarr = new Array();var cyposarr = new Array();


//news items
cyposarr[0]=0;cyposarr[1]=1;//start a new array

titlea[0] = "title";texta[0] = "headline";linka[0] = "url";trgfrma[0] = "";
titlea[1] = "title";texta[1] = "headline";linka[1] = "url";trgfrma[1] = "";

var mc=2;//how many elements

//news items






var inoout=false;

var spage;
var cvar=0,say=0,tpos=0,enson=0,hidsay=0,hidson=0;
var tmpv;
tmpv=236-8-8-(2*0);

var psy = new Array();
divtextb ="<div id=d";
divtev1=" onmouseover=\"mdivmo(";
divtev2=")\" onmouseout =\"restime(";
divtev3=")\" onclick=\"butclick(";
divtev4=")\"";
divtexts = " style=\"position:absolute;visibility:hidden;width:"+tmpv+"; COLOR: 000000; left:0; top:0; FONT-FAMILY: Arial; FONT-SIZE: 8pt; FONT-STYLE: normal; FONT-WEIGHT: normal; TEXT-DECORATION: none; margin:0px; overflow-x:hidden; LINE-HEIGHT: 12pt; text-align:left;padding:0px; cursor:'default';\">";
ns6span= " style=\"position:relative; COLOR: 9A0000; width:"+tmpv+"; FONT-FAMILY: Arial; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-WEIGHT: bold; TEXT-DECORATION: none; LINE-HEIGHT: 14pt; text-align:left;padding:0px;\"";

uzun="<div id=\"enuzun\" style=\"position:absolute;left:0;top:0;\">";
var uzunobj=null;
var uzuntop=0;
var toplay=0;

function mdivmo(gnum)
{
      inoout=true;

      if((linka[gnum].length)>2)
      {
            objd=document.getElementById('d'+gnum);
            objd2=document.getElementById('hgd'+gnum);

            objd.style.color="#3A3A3A";
            objd2.style.color="#D50000";

            objd.style.cursor='pointer';
            objd2.style.cursor='pointer';

            objd.style.textDecoration='none';objd2.style.textDecoration='none';

            window.status=""+linka[gnum];
      }
}

function restime(gnum2)
{
      inoout=false;
      
      objd=document.getElementById('d'+gnum2);
      objd2=document.getElementById('hgd'+gnum2);

      objd.style.color="#000000";
      objd2.style.color="#9A0000";

      objd.style.textDecoration='none';objd2.style.textDecoration='none';

      window.status="";
}

function butclick(gnum3)
{
if(linka[gnum3].substring(0,11)=="javascript:"){eval(""+linka[gnum3]);}else{if((linka[gnum3].length)>3){
if((trgfrma[gnum3].indexOf("_parent")>-1)){eval("parent.window.location='"+linka[gnum3]+"'");}else if((trgfrma[gnum3].indexOf("_top")>-1)){eval("top.window.location='"+linka[gnum3]+"'");}else{window.open(''+linka[gnum3],''+trgfrma[gnum3]);}}}

}

function dotrans()
{
      if(inoout==false){

      uzuntop--;
      if(uzuntop<(-1*toplay))
      {
            uzuntop=150;
      }

      uzunobj.style.top=uzuntop+"px";
}
      if(psy[(uzuntop*(-1))+4]==3)
      {
            setTimeout('dotrans()',3000+35);
      }
      else
      {
            setTimeout('dotrans()',35);
      }      
      
}


function initte2()
{
      i=0;
      for(i=0;i<mc;i++)
      {
            objd=document.getElementById('d'+i);
            heightarr[i]=objd.offsetHeight;
      }
      toplay=4;
      for(i=0;i<mc;i++)
      {
            objd=document.getElementById('d'+i);
            objd.style.visibility="visible";
            objd.style.top=""+toplay+"px";
            psy[toplay]=3;
            toplay=toplay+heightarr[i]+10;

      }

      uzunobj=document.getElementById('enuzun');
      uzunobj.style.left=8+"px";
      uzunobj.style.height=toplay+"px";
      uzunobj.style.width=tmpv+"px";
      uzuntop=150;
      dotrans();

}

function initte()
{
      i=0;
      innertxt=""+uzun;

      for(i=0;i<mc;i++)
      {
            innertxt=innertxt+""+divtextb+""+i+""+divtev1+i+divtev2+i+divtev3+i+divtev4+divtexts+"<div id=\"hgd"+i+"\""+ns6span+">"+titlea[i]+"<br></div>"+texta[i]+"</div>";
      }
      innertxt=innertxt+"</div>";
      spage=document.getElementById('spagens');

      spage.innerHTML=""+innertxt;

      spage.style.left="0px";
      spage.style.top="0px";

      setTimeout('initte2()',500);

}


window.onload=initte;
0
Comment
Question by:melkordy
  • 2
4 Comments
 
LVL 55

Accepted Solution

by:
Ryan Chong earned 1500 total points
ID: 16427418
>>Can i include .asp or .cfm files in .js?

try do it in this way...

try rename your .js file to .asp or .cfm file, so that it can be run on server side. Since it's running on server side, you can generate the portion of js file dynamically via server side scripting.

Get the idea?

Hope this helps
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 16427675
>>Can i include .asp or .cfm files in .js?
NO.

You cannot!

They must be processed by the server, whereas .js is a javascript file that is only run on the client.

Now you can have variables sent from asp or cfm to the js.  not to the file, but into variables, that thte file can read...
0
 
LVL 55

Expert Comment

by:Ryan Chong
ID: 16427883
>>try rename your .js file to .asp or .cfm file, so that it can be run on server side
yup, rename it so that it can run on server side, and then use it as an include file to your original page. Hope this is clear.
0
 

Author Comment

by:melkordy
ID: 16428969
I changed the .js to .cfm

the .cfm page have no html tags only the code below.  when i add the HTML tags or <cfquery> it just stopped running.  I put that code within <script langauage"javascript"></script> tags and it didn't do nothing.  any hints?






var titlea = new Array();var texta = new Array();var linka = new Array();var trgfrma = new Array();var heightarr = new Array();var cyposarr = new Array();

cyposarr[0]=0;
titlea[0] = "title";texta[0] = "headline";linka[0] = "url";trgfrma[0] = " ";
var mc=1;



var inoout=false;
var tmpv;
tmpv=236-8-8-2*parseInt(0);
var cvar=0,say=0,tpos=0,enson=0,hidsay=0,hidson=0;
var psy = new Array();
divtextb ="<div id=d";
divtev1=" onmouseover=\"mdivmo(";
divtev2=")\" onmouseout =\"restime(";
divtev3=")\" onclick=\"butclick(";
divtev4=")\"";
divtexts = " style=\"position:absolute;visibility:hidden;width:"+tmpv+"; COLOR: #000000; left:0; top:0; FONT-FAMILY: Arial; FONT-SIZE: 8pt; FONT-STYLE: normal; FONT-WEIGHT: normal; TEXT-DECORATION: none; margin:0px; overflow-x:hidden; LINE-HEIGHT: 12pt; text-align:left;padding:0px; cursor:'default';\">";
ie6span= " style=\"position:relative; COLOR: #9A0000; width:"+tmpv+"; FONT-FAMILY: Arial; FONT-SIZE: 9pt; FONT-STYLE: normal; FONT-WEIGHT: bold; TEXT-DECORATION: none; LINE-HEIGHT: 14pt; text-align:left;padding:0px;\"";
uzun="<div id=\"enuzun\" style=\"position:absolute;left:0;top:0;\">";
var uzunobj=null;
var uzuntop=0;
var toplay=0;
function mdivmo(gnum)
{
      inoout=true;

      if((linka[gnum].length)>2)
      {
      objd=eval("d"+gnum);
      objd2=eval("hgd"+gnum);

      objd.style.color="#3A3A3A";
      objd2.style.color="#D50000";

      objd.style.cursor='hand';
      objd2.style.cursor='hand';

      objd.style.textDecoration='none';objd2.style.textDecoration='none';

}
      window.status=""+linka[gnum];

}

function restime(gnum2)
{
      inoout=false;
      objd=eval("d"+gnum2);
      objd2=eval("hgd"+gnum2);

      objd.style.color="#000000";
      objd2.style.color="#9A0000";

      objd.style.textDecoration='none';objd2.style.textDecoration='none';

      window.status="";

}

function butclick(gnum3)
{
if(linka[gnum3].substring(0,11)=="javascript:"){eval(""+linka[gnum3]);}else{if((linka[gnum3].length)>3){
if((trgfrma[gnum3].indexOf("_parent")>-1)){eval("parent.window.location='"+linka[gnum3]+"'");}else if((trgfrma[gnum3].indexOf("_top")>-1)){eval("top.window.location='"+linka[gnum3]+"'");}else{window.open(''+linka[gnum3],''+trgfrma[gnum3]);}}}


}

function dotrans()
{
      if(inoout==false){
      uzuntop--;
      if(uzuntop<(-1*toplay))
      {
            uzuntop=150;
      }

      enuzun.style.pixelTop=uzuntop;
}
      if(psy[(uzuntop*(-1))+4]==3)
      {
setTimeout('dotrans()',3000+35);
}
else{setTimeout('dotrans()',35);}

}

function initte2()
{
      i=0;
      for(i=0;i<mc;i++)
      {
            objd=eval("d"+i);
            heightarr[i]=objd.offsetHeight;
      }

      toplay=4;
      for(i=0;i<mc;i++)
      {
            objd=eval("d"+i);
            objd.style.visibility="visible";
            objd.style.pixelTop=toplay;
            psy[toplay]=3;
            toplay=toplay+heightarr[i]+10;

      }


      enuzun.style.left=8+"px";
      enuzun.style.height=toplay+"px";
      enuzun.style.width=tmpv+"px";
      uzuntop=150;



      dotrans();

}

function initte()
{
      i=0;
      innertxt=""+uzun;
      for(i=0;i < mc;i++)
      {
            innertxt=innertxt+""+divtextb+""+i+""+divtev1+i+divtev2+i+divtev3+i+divtev4+divtexts+"<span id=\"hgd"+i+"\""+ie6span+">"+titlea[i]+"</span><br>"+texta[i]+"</div>";
      }
      innertxt=innertxt+"</div>";

      spageie.innerHTML=""+innertxt;
      setTimeout('initte2()',500);
}
window.onload=initte;
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Over time, the online landscape has altered considerably, but that’s nothing compared to the up-and-coming trends that will shape the web design industry in the coming year. Keep reading to find out which trends will shape B2B web design in 2018.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question