Page 1 of 1

Words into Image Alt tags

Posted: Mon Nov 20, 2006 10:13 am
by NotOnUrNelly
Hi All,

Just wondering whether this can be done.

I have a text field from a database. I need this to be displayed in a table, but the text is varying lengths and makes my tables look unsightly. The text is not essential and an option I am considering is having a small image appear in the last column of my table if the field has a value.

When the image is hovered I want the text to be displayed in the alt tag.

I have used the following code to try to achieve this

Code: Select all

<?php 
		   if ($Issues){ ?>
		<img src="images/title.jpg" width="10" height="10" alt = <?php echo $Issues;?>>
		<?php
		  }
		  ?>
This code only produces the first word when the image is hovered.

Many Thanks
Jamie

Posted: Mon Nov 20, 2006 10:21 am
by themurph
Add double quotes for the alt= attribute

Something like:

Code: Select all

<?php
if ($Issues) {
     echo "<img src=\"images/title.jpg\" width=\"10\" height=\"10\" alt=\"$Issues\">\n";
}
?>

Posted: Mon Nov 20, 2006 10:28 am
by NotOnUrNelly
Many Thanks for that it worked a treat.

Jamie

Posted: Mon Nov 20, 2006 11:19 am
by RobertGonzalez
This applies to any HTML tag attribute that accepts spaced strings in them (like the value attribute of the <input> tag). In fact, to be compliant with XHTML or STRICT HTML standard, all of your HTML element attributes must be wrapped in double quotes.