homepage Welcome to WebmasterWorld Guest from 54.198.42.105
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
onLoad problem
greencode




msg:4512153
 8:28 am on Oct 25, 2012 (gmt 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>

 

greencode




msg:4512203
 10:31 am on Oct 25, 2012 (gmt 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>

JAB Creations




msg:4512388
 7:30 pm on Oct 25, 2012 (gmt 0)

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

incrediBILL




msg:4514416
 11:09 pm on Oct 31, 2012 (gmt 0)

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved