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



Reply
Old 10-11-2006, 06:29 AM Conflicting JS code?
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Hey

I have a page that I'm trying to add a client-side validation script to (downloaded from http://www.vikaskbh.com/) it works great in the other pages i have added it to but not so in a page which already contains some JavaScript.

I think it may have something to do with both of the scripts containing an "window.onLoad" part which may conflict with each other (may be completely off but a thought...

I have experimented with the order in which the code is included and i can get both of the bits to work but just not at the same time

Is there a way in which i can combine the two onLoad pieces so they run at the same time (if this is, infact, the problem)

Ill just include the onLoad line here but ill link it incase you want to see the entire script.

Code:
var hiddenDivs = new Array();

window.onload = function() {
	//gets the all hidden divs so we can reset them all to hidden when we choose a new one
	var myDivs = document.getElementsByTagName("DIV");
	for (i=0; i<myDivs.length; i++) {
		if (myDivs[i].className == "city") {
			//hide them as we enter them into the array - if JS is on - they're hidden, and if JS is off we still see al of them
			myDivs[i].className = "hiddenCity";
			hiddenDivs.push(myDivs[i]);
		}
	}
}
Validation:
Code:
window.onload = getFormDetails;

//code omitted..
function getFormDetails()
{
	numberOfForms = document.forms.length;
	if(numberOfForms!=0)setUpValidation();
	else return;
}

Thanks a lot for any help
Stoot

Full Validate Code
stoot98 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-11-2006, 10:36 AM Re: Conflicting JS code?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I fixed the one line of your "partner" script's code:
Code:
var hiddenDivs = new Array(); function getHiddenDivs() { //gets the all hidden divs so we can reset them all to hidden when we choose a new one var myDivs = document.getElementsByTagName("DIV"); for (i=0; i<myDivs.length; i++) { if (myDivs[i].className == "city") { //hide them as we enter them into the array - if JS is on - they're hidden, and if JS is off we still see al of them myDivs[i].className = "hiddenCity"; hiddenDivs.push(myDivs[i]); } } }
Then, in your HTML:
Code:
<body onload="getFormDetails();getHiddenDivs();">
By using the onload attribute of the body tag, you can load as many functions as you want. Just be careful not to go overboard.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-11-2006, 12:01 PM Re: Conflicting JS code?
stoot98's Avatar
Ultra Talker

Posts: 427
Name: Stuart
Location: Glasgow, Scotland
Trades: 0
Excellent! Works a dream...

Thanks a lot
Stoot
stoot98 is offline
Reply With Quote
View Public Profile
 
Old 10-16-2006, 04:06 AM Re: Conflicting JS code?
seomumbai's Avatar
Skilled Talker

Posts: 98
Trades: 0
you can't open two functions in a window onload. be sure to call the second function in the first one and then call the first function in the onload of a window.
seomumbai is offline
Reply With Quote
View Public Profile
 
Old 10-16-2006, 11:37 AM Re: Conflicting JS code?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Ummm...yes you can. You can open as many functions as you want in a body onload attribute.

Read what I posted for a solution. Not only can it be done, the answer is two posts above what you just said.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)

Last edited by ADAM Web Design; 10-16-2006 at 11:38 AM..
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-16-2006, 08:35 PM Re: Conflicting JS code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
To add what Adam said, you can call as many as you want as long as you don't place a return in your calls.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 10-16-2006, 08:52 PM Re: Conflicting JS code?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Sorry, that's right. I usually don't use return in my calls so I forgot about that.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 10-17-2006, 01:39 AM Re: Conflicting JS code?
seomumbai's Avatar
Skilled Talker

Posts: 98
Trades: 0
I think we can't call two onload functions at the same time.
seomumbai is offline
Reply With Quote
View Public Profile
 
Old 10-17-2006, 01:43 AM Re: Conflicting JS code?
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Dude...look at the freakin' code I posted the first time around!
Look at how buddy said it worked for him!
Try it!

THE ANSWER IS RIGHT UNDER YOUR **** NOSE. JUST LOOK FOR IT.

Can't find it? The answer is here:

http://www.webmaster-talk.com/javasc...tml#post293998

There you go. See it? Or do you need a skywriter to figure this one out?

In other words...the answer's there, now try it for yourself or shut up about it.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to Conflicting JS code?
 

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.41386 seconds with 12 queries