PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Fri Nov 17, 2017 7:51 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Wed Oct 19, 2016 3:21 pm 
Offline
Forum Newbie

Joined: Thu Feb 05, 2015 3:34 pm
Posts: 21
Hi All,

Appreciate help in resolving the below issues.....

With every refresh I wanted to change the text color in marquee tag by calling javascript function......
I am getting color code like #18EEC5 ......but when calling script function from marquee tag nothing is happening......

Syntax: [ Download ] [ Hide ]
<html>
    <head>
                <script type="text/javascript">
                                function getRandomColor() {
                                var letters = '0123456789ABCDEF';
                                var color = '#';
                                for (i = 0; i < 6; i++ ) {
                                        color += letters[Math.floor(Math.random() * 16)];
                                }
                                return color;
                                }                              
                </script>
        </head>
    <body>     
                        <script>
                                $col=getRandomColor();
                                document.write(getRandomColor());                                              
                        </script>
                        <marquee style="color: 'document.write(getRandomColor())'; font-size: 20pt; font-weight: bold">
                                Text Color Changes
                        </marquee>
        </body>
</html>
 

Thanks,
Nick


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 1:03 am 
Offline
Spammer :|
User avatar

Joined: Wed Oct 15, 2008 2:35 am
Posts: 6577
Location: WA, USA
Javascript and CSS don't work that way.

If you want to change the color then you have to write some Javascript that uses the DOM to locate the <marquee> and change its text color. With that page you can do it by
Code:
document.getElementsByTagName("marquee")[0].style.color = getRandomColor();


Top
 Profile  
 
PostPosted: Thu Oct 20, 2016 6:55 pm 
Offline
Forum Newbie

Joined: Thu Feb 05, 2015 3:34 pm
Posts: 21
Hi,

Thx.....you are right......

Your help is highly appreciated.

Thanks,
Nick


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group