Chezshire Posted April 29, 2010 Share Posted April 29, 2010 Hello, I'm taking a class in JavaScript and have to do a project where we have to load several scripts which are designed to collide with one another. I have everything working in pieces, but as I'm trying to filter each script in, I am getting several (twice) error messages which display as follows 'JavaScript Error: obj.style is undefined'. After the error messages finish, the page loads and the file works - but I get those error messages so I know i've done something very boneheaded and would appreciate some guidance in how to properly define the 'obj.style' which i've clearly not done correctly. I'm very new and learning, help and guidance is very much appreciated. This is the offending script that is troubling me for the last 12 or so hours... <script type="text/JavaScript"> function makeMeRed(obj) {obj.style.color='red';} function makeMeNormal(obj) {obj.style.color='black';} function announceAssignment() {alert ( 'Image Fun house (Due Tuesday, May 4th) - Demonstrate Multiple types of Image Handling Events using JavaScript (No AJAX or Dogs Allowed!)' );} </script> This is my addOnLoad script as currently written <script type="text/javascript"> //place local js code here function init() {//a test function - replace with your cool code! alert("I'm init!"); //pun alert! } addOnload(init); //with addOnload() we can add as many functions as we wish to window.onload (one by one)! addOnload(makeMeRed); //red text '_js/announcement_a3.js' addOnload(makeMeNormal); //black text '_js/announcement_a3.js' addOnload(announceAssignment); //alert text '_js/announcement_a3.js' addOnload(myYear); //add myYear from '_js/myYear.js' </script> This is the portion of the html I am trying to write to <p><span onMouseOver="makeMeRed(this);" onMouseOut="makeMeNormal(this);" onclick="announceAssignment();"> Image Fun house (Due Tuesday, May 4th)<br /> Demonstrate Multiple types of Image Handling Events using JavaScript<br /> (No AJAX or Dogs Allowed!) </span> </p> This is the url of current file as currently written http://www.xdesignworks.com/SCC/web150/wk04_1.5.2-combine.html Please note that my site displays an alert saying 'no dogs or ajax allowed' - this is a 'in-class' joke regarding the assignment. We aren't allowed to use AJAX and the dog reference is just me being silly - I'm dog sitting for a friend and can't bring the dog to class, and have friends who watch him while I'm in class (he's very sweet, but very 'attention' starved it seems). Thank you one and all for any help, guidance and or understanding that any of you can help this newb (me!) with! -Chez Quote Link to comment https://forums.phpfreaks.com/topic/200213-javascript-error-objstyle-is-undefined-please-help-this-newb-college-student/ Share on other sites More sharing options...
KevinM1 Posted April 29, 2010 Share Posted April 29, 2010 From the looks of things, it appears that it's complaining that obj (your spans) are undefined at the time where you attempt to add the makeMe functions to window.onload, and therefore have no style attribute to refer to. Quote Link to comment https://forums.phpfreaks.com/topic/200213-javascript-error-objstyle-is-undefined-please-help-this-newb-college-student/#findComment-1050729 Share on other sites More sharing options...
Chezshire Posted April 29, 2010 Author Share Posted April 29, 2010 Thank you for the reply Nightslyr, So you're saying that the problem might be in my spans? How would I go about 'defining' these? - Chez (thanks for the reply NightSlyr!) Quote Link to comment https://forums.phpfreaks.com/topic/200213-javascript-error-objstyle-is-undefined-please-help-this-newb-college-student/#findComment-1050737 Share on other sites More sharing options...
Chezshire Posted April 29, 2010 Author Share Posted April 29, 2010 Hi NightSlyr, and a respectful hello to everyone else from a very green 'newbie'. I revised my function by removing the 'obj...' so it now reads as so (and it's working now without errors): <script type="text/JavaScript"> function makeMeRed(obj) {var color='red';} function makeMeNormal(obj) {var color='black';} function announceAssignment() {alert ( 'No AJAX or Dogs Allowed!' );} </script> Thank you for helping me to find some footing in the assignment so that I can progress onwards to the next part. I'm sure I'll be posting a few more questions here through out the weekend and incase I've not emphasised it enough, all help is welcome. thank you Nightslyr! -Chez Quote Link to comment https://forums.phpfreaks.com/topic/200213-javascript-error-objstyle-is-undefined-please-help-this-newb-college-student/#findComment-1050744 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.