Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2012, 10:10 PM   PM User | #1
fireplace_tea
New Coder

 
Join Date: Sep 2012
Location: Boulder, CO
Posts: 56
Thanks: 5
Thanked 0 Times in 0 Posts
fireplace_tea is an unknown quantity at this point
JavaScript File Size Limitation?

Hi Everyone,

For my website, I have a main.js file that is about 115 lines of code (3kb in size) and it all works well. However, when I added more coding it would not work and render other coding inoperable. When I put the added coding in a different .js (portfolio.js) file everything worked. Is this a file size limitation somewhere, somehow? I doublechecked and the variable and other names are all different. If this is not a size limit, any ideas to what it is?

Here is the main.js file coding:
Code:
window.onload = function(){
	navButtons();
	setFocus();
}

function navButtons(){
var homeb = document.getElementById("homeb");
var contactb = document.getElementById("contactb");
var portfoliob = document.getElementById("portfoliob");
homeb.onmouseover = function(){
	homeb.setAttribute("src", "images/home_button1.gif");
};
homeb.onmouseout = function(){
	homeb.setAttribute("src", "images/home_button.gif");
};
contactb.onmouseover = function(){
	contactb.setAttribute("src", "images/contact_button1.gif");
};
contactb.onmouseout = function(){
	contactb.setAttribute("src", "images/contact_button.gif");
};
portfoliob.onmouseover = function(){
	portfoliob.setAttribute("src", "images/portfolio_button1.gif");
};
portfoliob.onmouseout = function(){
	portfoliob.setAttribute("src", "images/portfolio_button.gif");
};
}

function setFocus(){
var cursorHere = document.getElementById("name");
cursorHere.focus();
}


var gettip = document.getElementById("gettip");
var changetip = document.getElementById("tooltip");
gettip.onmouseover = function(){
	changetip.setAttribute("id", "tooltipshow");
};
gettip.onmouseout = function(){
	changetip.setAttribute("id", "tooltip");
};


var formbg = document.getElementById("contactform").elements;
for(i=0; i<formbg.length; i++){
	if(formbg[i].className=="formbox"){
		formbg[i].onfocus=function(){
			this.style.backgroundColor = "#faffbd";
		}	
		formbg[i].onblur=function(){
			this.style.backgroundColor = "#ffffff";
		}
	}else{
		formbg[i].onmouseover = function(){
			this.style.backgroundColor = "green";
		}
		formbg[i].onmouseout = function(){
			this.style.backgroundColor = "#1e9cd7";
		}
	}
}


var errormsg = document.getElementById("errormsg");
var errortext = document.getElementById("errortext");
var namefield = document.getElementById("name");
var emailfield = document.getElementById("email");
var commentfield = document.getElementById("comment");
document.getElementById("contactform").onsubmit = function(){
	if(namefield.style.borderColor == "red" || emailfield.style.borderColor == "red" || commentfield.style.borderColor == "red"){
		namefield.style.borderColor = "#7EC1E7";
		emailfield.style.borderColor = "#7EC1E7";
		commentfield.style.borderColor = "#7EC1E7";
	} 
	
	if(emailfield.value == "" && namefield.value == ""){
		errormsg.style.display = "block";
		errortext.innerHTML = "Please enter both your name and email address.";
		namefield.style.borderColor = "red";
		emailfield.style.borderColor = "red";
		return false;
	} 
	else if(namefield.value == ""){
		errormsg.style.display = "block";
		errortext.innerHTML = "Please type in your name.";
		namefield.style.borderColor = "red";
		return false;
	}	
	else if(emailfield.value == ""){
		errormsg.style.display = "block";
		errortext.innerHTML = "Please enter in an email address.";
		emailfield.style.borderColor = "red";
		return false;
	}
	else if(commentfield.value == ""){
		errormsg.style.display = "block";
		errortext.innerHTML = "Please enter in a comment and/or question.";
		commentfield.style.borderColor = "red";
		return false;
	}
	else{
		errormsg.style.display = "none";
		return true;
	}
};


document.getElementById("contactform").onreset = function(){
	errormsg.style.display = "none";
	namefield.style.borderColor = "#7EC1E7";
	emailfield.style.borderColor = "#7EC1E7";
	commentfield.style.borderColor = "#7EC1E7";

Here is the portfolio.js coding:
Code:
var webborder = document.getElementById("html5link");
webborder.onmouseover = function(){
	webborder.style.borderColor = "#ffffff";
	webborder.style.borderStyle = "solid";
	webborder.style.borderWidth = "4px";
};
webborder.onmouseout = function(){
	webborder.style.borderColor = "#000000";
	webborder.style.borderStyle = "solid";
	webborder.style.borderWidth = "2px";
};


var websiteinfo = document.getElementById("getwebtext");
var websitetext = document.getElementById("webtext");
getwebtext.onmouseover = function(){
	websitetext.setAttribute("id", "webtextshow");
};
getwebtext.onmouseout = function(){
	websitetext.setAttribute("id", "webtext");
};

When I put the coding in file portfolio.js into the main.js file, the coding from portfolio.js will not work and render some of the main.js coding inoperable. But, putting the coding in two different files, as shown above, makes everything work just fine. Any ideas or insights would be great.

Thanks,
Julie

Last edited by fireplace_tea; 09-17-2012 at 10:54 PM..
fireplace_tea is offline   Reply With Quote
Old 09-17-2012, 10:15 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
115 is a small number of lines - there must be some other issue.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 09-17-2012, 10:38 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,452
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
The most common cause where adding extra code to the end of an existing JavaScript is where you add to the end of a line and omit the ; that ends the first statement.

That is not likely to be the cause in this instance but without seeing the actual code it is hard to say what the problem might be - but 115 lines is nowhere near the size that many JavaScript frameworks use successfully.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 09-17-2012, 11:06 PM   PM User | #4
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
You are missing a closing bracket and semi-colon }; at the end of main.js.
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 09-20-2012, 12:01 AM   PM User | #5
fireplace_tea
New Coder

 
Join Date: Sep 2012
Location: Boulder, CO
Posts: 56
Thanks: 5
Thanked 0 Times in 0 Posts
fireplace_tea is an unknown quantity at this point
Quote:
Originally Posted by AndrewGSW View Post
You are missing a closing bracket and semi-colon }; at the end of main.js.

I do have the missing closing bracket and the semi-colon in the original main.js file, they just didn't make it into this post (ooppsss). Thanks though.
fireplace_tea is offline   Reply With Quote
Old 09-20-2012, 12:07 AM   PM User | #6
fireplace_tea
New Coder

 
Join Date: Sep 2012
Location: Boulder, CO
Posts: 56
Thanks: 5
Thanked 0 Times in 0 Posts
fireplace_tea is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
The most common cause where adding extra code to the end of an existing JavaScript is where you add to the end of a line and omit the ; that ends the first statement.

That is not likely to be the cause in this instance but without seeing the actual code it is hard to say what the problem might be - but 115 lines is nowhere near the size that many JavaScript frameworks use successfully.
Hi Stephen,

Have you had a chance to look at the code (I added it a couple of days ago).

Thanks,
Julie
fireplace_tea is offline   Reply With Quote
Old 09-20-2012, 12:35 AM   PM User | #7
rnd me
Senior Coder

 
rnd me's Avatar
 
Join Date: Jun 2007
Location: Urbana
Posts: 3,455
Thanks: 9
Thanked 466 Times in 450 Posts
rnd me is a jewel in the roughrnd me is a jewel in the roughrnd me is a jewel in the rough
there is no size limit, i've loaded 10MB scripts without issue...

post your current code and we can offer better advise.
__________________
my site (updated 5/13)
STATS (2013/5) HTML5:90.2% MOB:14% IE7:0.5% IE8:8.6% IE9:9.8% IE10:10%
rnd me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 05:14 AM.


Advertisement
Log in to turn off these ads.