Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Closed Thread
Simple Background Change Issue...
Old 08-17-2008, 08:36 PM Simple Background Change Issue...
Skilled Talker

Posts: 70
Location: Atlanta, GA
Trades: 0
This is supposed to be a simple background color change using event handlers and I can't figure out why it's not working.

Code:
 
<html><head><title>Prob.11</title>
<script type="text/javascript">

function attachHandlers {

var the_opts=document.getElementsByTagName("input");

for (var i=0; i<the_opts.length; i++) {

 if ((the_opts[i].nodeName=="input")||
     (the_opts[i].nodeName=="INPUT"))
 {
   the_opts[i].onclick=changeBackground;
 }
}
},

function changeBackground(evt){

var purp_button = document.getElementById("first_button");
var yellow_button = document.getElementById("sec_button");
var pink_button = document.getElementById("third_button");
var black_button = document.getElementById("fourth_button");
var the_body = document.getElementsByTagName("body");

 if (!evt)
 {
  evt = event;
  this_sel = evt.srcElement;
 }
 else
 {
  this_sel = evt.target;
 }

 if (this_sel=purp_button)
  {
   the_body.style.bgColor="purple";
  }

 if (this_sel=yellow_button)
  {
   the_body.style.bgColor="yellow";
  }

 if (this_sel=pink_button)
  {
   the_body.style.bgColor="pink";
  }
 
 if (this_sel=black_button)
  {
   the_body.style.bgColor="black";
  }
}

</script></head>
<body bgColor="blue" onLoad="attachHandlers();">

<div class="the_buttons">
<input type="button" value="purple" id="first_button"><br>
<input type="button" value="yellow" id="sec_button"><br>
<input type="button" value="pink" id="third_button"><br>
<input type="button" value="black" id="fourth_button">
</div>
</body>
</html>
LayneMitch is offline
View Public Profile
 
 
Register now for full access!
Old 08-17-2008, 10:05 PM Re: Simple Background Change Issue...
Skilled Talker

Posts: 70
Location: Atlanta, GA
Trades: 0
Solved it already...Thanks...
LayneMitch is offline
View Public Profile
 
Closed Thread     « Reply to Simple Background Change Issue...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.29252 seconds with 12 queries