Link to home
Start Free TrialLog in
Avatar of azyet24
azyet24Flag for United States of America

asked on

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.
Avatar of Zyloch
Zyloch
Flag of United States of America image

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.
Avatar of azyet24

ASKER

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>
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.
ASKER CERTIFIED SOLUTION
Avatar of AtanAsfaloth
AtanAsfaloth

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of azyet24

ASKER

AtanAsfaloth,

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