CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Perl variable as value of HTML attribute

 



Alpha1980
Novice

Dec 29, 2006, 9:24 AM

Post #1 of 5 (463 views)
Perl variable as value of HTML attribute Can't Post

Hi,

Please look at the HTML code within a Perl document below.

There are two variables, "$one" is the value within a <p> element.

The other variable, "$two" is the value of the "id" attribute of a <p> element.

Is it correct syntax to write this code as

Code
id="$two"

and will Perl replace "$two" with it's correct value?

I appreciate any advice on this subject.

Many Thanks. Smile


Code
<<"EOF"; 
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>

<body>

<div class="form">
<p class="text" id="one">$one</p>
<p class="text" id="$two">X</p>
</div>

</body>
</html>
EOF



KevinR
Veteran


Dec 29, 2006, 10:29 AM

Post #2 of 5 (459 views)
Re: [Alpha1980] Perl variable as value of HTML attribute [In reply to] Can't Post

The short answer is yes, it will work. If it's not working for you then you are doing something wrong, but you have not posted enough information to know why.

Where are $one and $two defined in your script?
-------------------------------------------------


Alpha1980
Novice

Dec 30, 2006, 8:19 AM

Post #3 of 5 (455 views)
Re: [KevinR] Perl variable as value of HTML attribute [In reply to] Can't Post


In Reply To
The short answer is yes, it will work. If it's not working for you then you are doing something wrong, but you have not posted enough information to know why.

Where are $one and $two defined in your script?

Thanks Kevin. Smile

It is working for me now.

I do have another question though. How can I add characters to the $two attribute value without making it part of the variable name? Example:


Code
<<"EOF";  
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="../css/styles.css"/>
</head>

<body>

<div class="form">
<p class="text" id="one">$one</p>
<p class="text" id="$two_2">X</p>
</div>

</body>
</html>
EOF


Thanks again.


KevinR
Veteran


Dec 30, 2006, 9:56 AM

Post #4 of 5 (454 views)
Re: [Alpha1980] Perl variable as value of HTML attribute [In reply to] Can't Post

a couple of ways


Code
<p class="text" id="${two}_2">X</p>


or:


Code
<p class="text" id="$two\_2">X</p>

-------------------------------------------------


Alpha1980
Novice

Dec 30, 2006, 4:23 PM

Post #5 of 5 (452 views)
Re: [KevinR] Perl variable as value of HTML attribute [In reply to] Can't Post


In Reply To
a couple of ways


Code
<p class="text" id="${two}_2">X</p>


or:


Code
<p class="text" id="$two\_2">X</p>


Arggghhh!

I had the second one but with / instead of \.

Thanks again Kevin. Smile

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives