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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 259
  • Last Modified:

Hyperlink within array

I have a javascript that displays information like a ticker.  I would like to hyperlink the text but I can't get it to work.  Please help!

here's the var line:

var line=new Array()
line[1]="line 1 info"
line[2]="line 2 info"


I've tried
line[1]="<a href=""/index"">" & "line 1 info" & "</a>"

This didn't work though.
0
azyet24
Asked:
azyet24
  • 2
  • 2
1 Solution
 
ZylochCommented:
Try:

line[1] = '<a href="/index">line 1 info</a>';

Javascript first of all uses +, not & as the concatenation operator and does not use VB standards of extra quotes. Instead, once you run out of single/double quotes, you need to escape quotes with the backslash.
0
 
azyet24Author Commented:
Thanks for your help, but that didn't work.  It just printed out what you wrote instead of using the html behind it.  Maybe the entire code will help:

 <script language="JavaScript1.2">
<!--

/*
Typing Scroller
Submitted by bengaliboy00@hotmail.com (hp: http://www.angelfire.com/nt/bengaliboy/)
With modifications by Dynamicdrive.com
For full source code, usage terms, and 100s more scripts, visit http://dynamicdrive.com
*/

//Secify scroller contents
var line=new Array()
line[1]="This is an awsome script"
line[2]="It brings up the text you want..."
line[3]="One letter at a time"
line[4]="You can add and subtract lines as you like."
line[5]="It\'s very cool and easy to use"

//Specify font size for scoller
var ts_fontsize="12px"

//--Don't edit below this line

var longestmessage=1
for (i=2;i<line.length;i++){
if (line[i].length>line[longestmessage].length)
longestmessage=i
}

//Auto set scroller width
var tscroller_width=line[longestmessage].length

lines=line.length-1 //--Number of lines

//if IE 4+ or NS6
if (document.all||document.getElementById){
document.write('<form name="bannerform">')
document.write('<input type="text" name="banner" size="'+tscroller_width+'"')
document.write('  style="background-color:#333333; color:white; font-family: verdana; font-size: '+ts_fontsize+'; font-weight:bold; border: medium none" onfocus="blur()">')
document.write('</form>')
}

temp=""
nextchar=-1;
nextline=1;
cursor="_"
function animate(){
if (temp==line[nextline] & temp.length==line[nextline].length & nextline!=lines){
nextline++;
nextchar=-1;
document.bannerform.banner.value=temp;
temp="";
setTimeout("nextstep()",2000)}
else if (nextline==lines & temp==line[nextline] & temp.length==line[nextline].length){
nextline=1;
nextchar=-1;
document.bannerform.banner.value=temp;
temp="";
setTimeout("nextstep()",2000)}
else{
nextstep()}}

function nextstep(){

if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}


nextchar++;
temp+=line[nextline].charAt(nextchar);
document.bannerform.banner.value=temp+cursor
setTimeout("animate()",50)}

//if IE 4+ or NS6
if (document.all||document.getElementById)
window.onload=animate
// -->
</script>
0
 
ZylochCommented:
I just took a cursory overlook of your code since I'm in class right now (-_-) but it seems that the Javascript is using a form field. Form fields, of course, cannot display HTML. Instead, you need a script that manipulates the DOM or at the very least uses innerHTML somehow. I would recommend checking out http://www.dynamicdrive.com/ as they have many well-made DHTML scripts that allow HTML as input.
0
 
AtanAsfalothCommented:
Well, I edited the script a little. Zyloch was right it was in a textbox so that needed to be rewritten into a html container...
This is the new script. I added a new line and that is a hyperlink to this question






<script language="JavaScript1.2">
<!--

/*
Typing Scroller
Submitted by bengaliboy00@hotmail.com (hp: http://www.angelfire.com/nt/bengaliboy/)
With modifications by Dynamicdrive.com
For full source code, usage terms, and 100s more scripts, visit http://dynamicdrive.com
*/

//Secify scroller contents
var line=new Array()
var link=new Array()
line[1]="This is an awsome script"
link[1]="";
line[2]="It brings up the text you want..."
link[2]="";
line[3]="One letter at a time"
link[3]="";
line[4]="You can add and subtract lines as you like."
link[4]="";
line[5]="It\'s very cool and easy to use"
link[5]="";
line[6]="And you can even use Hyperlinks";
link[6]="http://www.experts-exchange.com/Web/Web_Languages/JavaScript/Q_21797177.html";

//Specify font size for scoller
var ts_fontsize="12px"

//--Don't edit below this line

var longestmessage=1
for (i=2;i<line.length;i++){
if (line[i].length>line[longestmessage].length)
longestmessage=i
}

//Auto set scroller width
var tscroller_width=line[longestmessage].length

lines=line.length-1 //--Number of lines

//if IE 4+ or NS6
if (document.all||document.getElementById){
document.write('<SPAN ID="bannerlink"><SPAN ID="banner" style="width:'+tscroller_width * 7+'px;  background-color:#333333; color:white; font-family: verdana; font-size: '+ts_fontsize+'; font-weight:bold; border: medium none" onfocus="blur()"></SPAN>')
}

var linktext = "";
var linktextend = "";

temp=""
nextchar=-1;
nextline=1;
cursor="_"
function animate(){
if (nextchar == 0) {
if(link[nextline] != "") {
linktext = '<A HREF="'+link[nextline]+'">';
linktextend = '</A>';
} else {
linktext = '';
linktextend = '';
}
}

if (temp==line[nextline] & temp.length==line[nextline].length & nextline!=lines){
nextline++;
nextchar=-1;

document.getElementById('banner').innerHTML=linktext+temp+linktextend
temp="";
setTimeout("nextstep()",2000)}
else if (nextline==lines & temp==line[nextline] & temp.length==line[nextline].length){
nextline=1;
nextchar=-1;
document.getElementById('banner').innerHTML=linktext+temp+linktextend
temp="";
setTimeout("nextstep()",2000)}
else{
nextstep()}}

function nextstep(){

if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}
else if (cursor=="_"){
cursor="_"}


nextchar++;
temp+=line[nextline].charAt(nextchar);
document.getElementById('banner').innerHTML=linktext+temp+cursor+linktextend
setTimeout("animate()",50)}

//if IE 4+ or NS6
if (document.all||document.getElementById)
window.onload=animate
// -->
</script>
0
 
azyet24Author Commented:
AtanAsfaloth,

That's awsome!  thanks for your help, that's exactly what I needed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now