Welcome to WebmasterWorld Guest from 54.224.158.39

Forum Moderators: open

Message Too Old, No Replies

onLoad problem

     
8:28 am on Oct 25, 2012 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:July 4, 2007
posts: 193
votes: 0


I found this script on JS Fiddle and it uses onLoad but when I create the HTML myself I can't get it to function at all. I'm sure this is just a basic issue!

Any help would be greatly appreciated…


<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN">
<html>
<head>
<title></title>
<style type="text/css">
.Default {
background-color:white
}

.Black {
background-color:black;
color:white
}

.Blue {
background-color:Cyan;
}

.Brown {
background-color:brown;
}

.Green {
background-color:green;
}

.Gray {
background-color:gray;
}

.Lime {
background-color:lime;
}

.Orange {
background-color:orange;
}
</style>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var selectedScheme = 'Default';

$('#color_scheme').change(function(){
$('span').removeClass(selectedScheme).addClass($(this).val());
selectedScheme = $(this).val();
});
</script>
</head>
<body>
<select name="color_scheme" id="color_scheme">
<option selected="selected">Default</option>
<option>Black</option>
<option>Blue</option>
<option>Brown</option>
<option>Green</option>
<option>Gray</option>
<option>Lime</option>
<option>Orange</option>
</select>
<span class="Default">Some text here</span>
</body>
</html>
10:31 am on Oct 25, 2012 (gmt 0)

Junior Member

10+ Year Member Top Contributors Of The Month

joined:July 4, 2007
posts: 193
votes: 0


Ah ha, figured it out…


<script type="text/javascript">
var selectedScheme = 'Default';
$(document).ready(function() {
$('#color_scheme').change(function(){
$('span').removeClass(selectedScheme).addClass($(this).val());
selectedScheme = $(this).val();
});
});
</script>
7:30 pm on Oct 25, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member jab_creations is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Aug 26, 2004
posts:3168
votes: 22


Yeah, don't use jQuery or any other frameworks, you'll rob yourself of learning anything meaningful, bloat the browser, unintentionally gimp the DOM with innerHTML which you should never ever use and introduce so many problems you'll be stuck in an infinite loop of suck.

Also there is no such mime as "text/javascript" though it is required for IE8 and older and Opera 8.x (but not 7.x/older or 9.x/newer) for those browsers to correctly execute scripts. Once you've used DOM object detection have the server serve application/javascript for compliant browsers and text/javascript if you plan on supporting legacy browsers.

- John
11:09 pm on Oct 31, 2012 (gmt 0)

Administrator from US 

WebmasterWorld Administrator incredibill is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Jan 25, 2005
posts:14664
votes: 99


don't use jQuery or any other frameworks, you'll rob yourself of learning anything meaningful


Nonsense. I'm all in favor of everyone learning the basics but there's no reason to not use code libraries instead of reinventing the wheel. Sorry, but I'm a long time programmer and telling people not to use libraries and templates, leveraging existing work to speed up the process, is bad advice.

Plus using jQuery helps the site owner find other people that can help maintain the site for less expense because many use jQuery and it's less expensive to maintain than having to learn someone's unique code from scratch.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members