Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    17
    Thanked 0 Times in 0 Posts

    Formatting array text

    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:
    Code:
    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>"
    	);

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Where and how are you trying to use the "Text" array?

    But just guessing, I think you might want to change to this...
    Code:
    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>'
    	);
    Last edited by jmrker; 07-26-2010 at 02:38 AM.

  • Users who have thanked jmrker for this post:

    rettgoings (07-26-2010)

  • #3
    New Coder
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    17
    Thanked 0 Times in 0 Posts
    All of my code:
    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:
    Code:
    <div id="mainText" class="text1"></div>

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,919
    Thanks
    79
    Thanked 4,423 Times in 4,388 Posts
    You declared it all wrong!!!

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

    Should be:
    Code:
    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,
    Code:
    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:
    Code:
    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.
    Last edited by Old Pedant; 07-26-2010 at 06:06 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    rettgoings (07-26-2010)

  • #5
    New Coder
    Join Date
    Jul 2010
    Posts
    37
    Thanks
    17
    Thanked 0 Times in 0 Posts
    Thank you both. Got it to work.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •