...

View Full Version : Formatting array text



rettgoings
07-26-2010, 02:20 AM
I have text being called from an array, however my HTML formatting in the array is not working.

How do I add formatting to text in an array? Also how do I make a portion of the array a link?

For example:

var Text = new Array(
"<br /><font style="color:red">URL:</font> <a href="www.google.com">www.google.com</a>",
"<br /><font style="color:red">URL:</font> <a href="www.yahoo.com">www.yahoo.com</a>"
);

jmrker
07-26-2010, 03:33 AM
Where and how are you trying to use the "Text" array?

But just guessing, I think you might want to change to this...


var Text = new Array(
'<br /><font style="color:red">URL:</font> <a href="www.google.com">www.google.com</a>',
'<br /><font style="color:red">URL:</font> <a href="www.yahoo.com">www.yahoo.com</a>'
);

rettgoings
07-26-2010, 04:05 AM
All of my code:

//<!--
var imgList = new Array(
"images/gallery/1.jpg",
"images/gallery/2.jpg"
);

var Text = clientData Array(
"<br /><font style="color:red">URL:</font> <a href="www.google.com">www.google.com</a>",
'<br /><font style="color:red">URL:</font> <a href="www.yahoo.com">www.yahoo.com</a>"
);

var currentMain = 0;
var currentMainT = 0;
var current_position=0;
var all_links="";

function init(){
all_links=document.getElementById('gallery').getElementsByTagName('a');
all_links[0].style.color="#7d3d3d";
ShowMain(current_position);
}

function color_me(element,color){
element.style.color=color;
}

function Prev(){
color_me(all_links[current_position],'#000000');
if((current_position-1)>-1){
current_position=current_position-1;
}
else{
current_position=(all_links.length-1);
}
ShowMain(current_position);
// ShowMainT(current_position);
color_me(all_links[current_position],'#7d3d3d');
}

function direct_selection(number){
all_links[current_position].style.color="#000000";
current_position=number;
ShowMain(current_position);
all_links[current_position].style.color="#7d3d3d";
}

function Next() {
color_me(all_links[current_position],'#000000');
if((current_position+1)<all_links.length){
current_position++;
}
else{
current_position=0;
}
ShowMain(current_position);
// ShowMainT(current_position);
color_me(all_links[current_position],'#7d3d3d');
}

function ShowMain(which){
currentMain = which;
currentMainT = which;
if ( currentMain < 0 ) currentMain = 0;
if ( currentMainT < 0 ) currentMainT = 0;
if ( currentMain > imgList.length-1) currentMain = imgList.length-1;
if ( currentMainT > clientData.length-1) currentMainT = clientData.length-1;
document.getElementById('mainImg').src = imgList[currentMain];
document.getElementById('mainText').innerHTML = clientData[currentMainT];
var PD = document.getElementById('Pg');
var PD2 = document.getElementById('Pg2');

document.getElementById("mainText").style.display = 'inline';
// return false;
}

onload = function() { ShowMain(0); }
onload = function() { ShowMainT(0); }
//-->


//<!--
function preloader(){
// counter
var i = 0;

// create object
imageObj = new Image();

// set image list
images = new Array();
images[0]="images/gallery/1.jpg";
images[1]="images/gallery/2.jpg";


// start preloading
for(i=0; i<=3; i++){
imageObj.src=images[i];
}
}
//-->


Output Here:

<div id="mainText" class="text1"></div>

Old Pedant
07-26-2010, 06:48 AM
You declared it all wrong!!!

And you missed change one pair of "..." to '...'.

Should be:


var clientData = new Array(
'<br /><font style="color:red">URL:</font> <a href="www.google.com">www.google.com</a>',
'<br /><font style="color:red">URL:</font> <a href="www.yahoo.com">www.yahoo.com</a>'
);

Or, slightly better,


var clientData = [
'<br /><font style="color:red">URL:</font> <a href="www.google.com">www.google.com</a>',
'<br /><font style="color:red">URL:</font> <a href="www.yahoo.com">www.yahoo.com</a>'
];

You *CAN* do this:


var clientData = [
"<br /><font style=\"color:red\">URL:</font> <a href=\"www.google.com\">www.google.com</a>",
"<br /><font style=\"color:red\">URL:</font> <a href=\"www.yahoo.com\">www.yahoo.com</a>"
];

but why? Use '...' to wrap " marks. Use "..." to wrap apostrophes.

rettgoings
07-26-2010, 06:51 AM
Thank you both. Got it to work.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum