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

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 04-21-2012, 08:21 PM   PM User | #1
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Unhappy Can 2 different .js files work together?

Ok I am sorry for the Noob question but is there a way to get 2 .js files to work?

I am trying to implement 2 different elements in to my website that call on 2 different .js files but one keeps the other from working..

Again I am sorry I am sure it is a dumb question but here is the code I am referring to

PHP Code:
    <script src="test/login_panel/js/slide.js" type="text/javascript"></script>
    
    <?php echo $script?>
    
<script src="prototype.js" type="text/javascript"></script>
The slide.js stops working when I place the prototype.js line in my <head> section
red71chevelle is offline   Reply With Quote
Old 04-21-2012, 10:10 PM   PM User | #2
Taro
Regular Coder

 
Taro's Avatar
 
Join Date: Oct 2011
Location: Geraldton, Ontario
Posts: 155
Thanks: 1
Thanked 1 Time in 1 Post
Taro is an unknown quantity at this point
Hello,

Instead you can try to put the JavaScript/ PHP within the source code page/ HTML page. This minimizes the possibility of an external scripting error.

Code:
<script type="text/javascript">
xxxxx
</script>
__________________
Element ID

Webs Support Helper

Your friendly neighborhood Taroman.
Taro is offline   Reply With Quote
Old 04-21-2012, 10:49 PM   PM User | #3
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
If the two JavaScript files contained correctly written JavaScript then you'd be able to simply include script tags for both in your page and both would work.

That they don't work means that neither script is written properly and has exposed variables or event handlers that the other script has also left exposed and those are clashing.

You should rewrite at least one and preferably both scripts to remove whatever it is they are placing in the global space so that they can no longer interfere with anything else in the page.

Whatever you do - don't jumble the JavaScript into the HTML file as that will just make things worse.
__________________
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 04-22-2012, 11:44 AM   PM User | #4
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
Also, the file prototype.js sounds like the JavaScript framework of that same name. What code does slide.js contain? Perhaps changing the order of inclusion would help (i. e. prototype.js first and then slide.js below that.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 04-22-2012, 04:10 PM   PM User | #5
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Thanks for the replies guys.. Just to see I placed prototype.js first and it didnt do anything here is thed code thats in the slide.js
Code:
$(document).ready(function() {
	
	// Expand Panel
	$("#open").click(function(){
		$("div#panel").slideDown("slow");
	
	});	
	
	// Collapse Panel
	$("#close").click(function(){
		$("div#panel").slideUp("slow");	
	});		
	
	// Switch buttons from "Log In | Register" to "Close Panel" on click
	$("#toggle a").click(function () {
		$("#toggle a").toggle();
	});		
		
});
The code for prototype.js its too long to post in this one and to be honest I am not great at understanding JS code.. What it is for is a newsletter subscription. I will post in in the next comment
red71chevelle is offline   Reply With Quote
Old 04-22-2012, 04:14 PM   PM User | #6
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Well it wont fit even in its own post sorry... it is huge it is 2552 lines
red71chevelle is offline   Reply With Quote
Old 04-22-2012, 04:17 PM   PM User | #7
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
There we go. That looks like jQuery in there. You shouldn’t use two different JavaScript frameworks at once. Decide for one, either prototype or jQuery, and stick with it.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 04-22-2012, 05:01 PM   PM User | #8
Kor
Red Devil Mod


 
Kor's Avatar
 
Join Date: Apr 2003
Location: Bucharest, ROMANIA
Posts: 8,478
Thanks: 58
Thanked 379 Times in 375 Posts
Kor has a spectacular aura aboutKor has a spectacular aura about
Or learn JavaScript language. If so, you will be able either to create your own codes or to understand what the varied JS frameworks do in order to avoid the collision.
__________________
KOR
Offshore programming
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
Kor is offline   Reply With Quote
Old 04-22-2012, 08:04 PM   PM User | #9
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Prototype only has $() exposed

jQuery has jQuery() exposed and also $() if you don't set the noconflict option.
__________________
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 04-23-2012, 03:02 AM   PM User | #10
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Dang Ok so I wont be able to use those 2 together then unless I learn JavaScript... Anyone know of a easy Newsletter signup script I will be able to use in place of this one?
red71chevelle is offline   Reply With Quote
Old 04-23-2012, 10:08 AM   PM User | #11
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
What are you trying to do with the prototype script? I’m sure there is a plugin with similar functionality for jQuery.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 04-23-2012, 02:50 PM   PM User | #12
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
I would love to use jquery for it. What I have done with jquery so far has been great!

It is just a simple form where a user would enter their name and their email address and then click signup and the prototype.js will validate what they entered to be a true email address and after it passes it to my database it will display a thank you below the form boxes

Here is the example and where I got the code from

http://www.designerfreesolutions.com...hp/default.php
red71chevelle is offline   Reply With Quote
Old 04-23-2012, 03:37 PM   PM User | #13
VIPStephan
The fat guy next door


 
VIPStephan's Avatar
 
Join Date: Jan 2006
Location: Halle (Saale), Germany
Posts: 7,697
Thanks: 5
Thanked 875 Times in 850 Posts
VIPStephan is a jewel in the roughVIPStephan is a jewel in the roughVIPStephan is a jewel in the rough
The JS cracks here will probably tell you that for such a simple action it’s overkill to use a JS framework and I agree. But I’m not enough of a JS crack to be able to give you a no-framework solution right away. Something similar to the example you showed can of course be achieved with the form plugin for jQuery. It probably requires a little more insight but the documentation is pretty good and you can always ask questions here, too, of course.
__________________
Don’t click this link!
VIPStephan is offline   Reply With Quote
Old 04-23-2012, 04:44 PM   PM User | #14
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Ok thanks.. I think I understand what I need to do but do you know where I can see an example of what the comment.php page might look like? I have this
PHP Code:
<?php 
    $host 
"****";
    
$user "****";
    
$password "****";
    
$database "****";
    
$server mysql_connect($host$user$password);
    
$connection mysql_select_db($database$server);

    function 
sql_quote($value) {
        
$value str_replace('<?','',$value);
        
$value str_replace('script','',$value);   
        if (
get_magic_quotes_gpc()) {
            
$value stripslashes($value);
        }
        if (!
is_numeric($value)) {
            
$value "'" mysql_real_escape_string($value) . "'";
        } else {
            if ((string)
$value[0] == '0') {
                
$value "'" mysql_real_escape_string($value) . "'";
        }}
        return 
$value;
    }
    
$q "INSERT INTO signups (email) VALUES (".sql_quote($_POST['email']).")";  

    
mysql_query($q);

?>
It was from another example I tried to use I assume it would look something like this but I am not sure how to get the 2 to work together...
red71chevelle is offline   Reply With Quote
Old 04-23-2012, 04:45 PM   PM User | #15
red71chevelle
New Coder

 
Join Date: Aug 2011
Posts: 80
Thanks: 19
Thanked 0 Times in 0 Posts
red71chevelle is an unknown quantity at this point
Also the issue I was having was getting JavaScript to validate that a user entered a valid email address. Not sure if that is posible with Jquery..
red71chevelle 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 11:57 PM.


Advertisement
Log in to turn off these ads.