Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 21
  1. #1
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder Taro's Avatar
    Join Date
    Oct 2011
    Location
    Geraldton, Ontario
    Posts
    155
    Thanks
    1
    Thanked 1 Time in 1 Post
    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.

  • #3
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,610
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #4
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    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.

  • #5
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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

  • #6
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Well it wont fit even in its own post sorry... it is huge it is 2552 lines

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    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.

  • #8
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    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
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #9
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,610
    Thanks
    0
    Thanked 645 Times in 635 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #10
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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?

  • #11
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    What are you trying to do with the prototype script? I’m sure there is a plugin with similar functionality for jQuery.

  • #12
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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

  • #13
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,624
    Thanks
    6
    Thanked 1,001 Times in 974 Posts
    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.

  • #14
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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...

  • #15
    New Coder
    Join Date
    Aug 2011
    Posts
    80
    Thanks
    19
    Thanked 0 Times in 0 Posts
    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..


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •