Multiple js script

Greetings!

Is the order of my external and internal js has something to do with the effectiveness of my code? I asked it because my datepickerUI tools didn’t work when I started to integrate it with other script, but when I tried in a single page it does.


<script src="date/jquery-1.7.1.js"></script>
	<script src="date/jquery.ui.core.js"></script>
	<script src="date/jquery.ui.widget.js"></script>
	<script src="date/jquery.ui.datepicker.js"></script>
	<script src="js/jquery.min.js"></script>
	<script src="js/jquery.placeholder.js"></script>
	<script type="text/javascript" src="js/mootools.js"></script>
	<script type="text/javascript">
		window.addEvent('domready', function(){
	                $('registerForm').addEvent('submit', function(e) {
	                    new Event(e).stop();
	                    var log = $('log_res').empty().addClass('ajax-loading');
	                    this.send({
	                        update: log,
	                        onComplete: function() {
	                            log.removeClass('ajax-loading');
	                        }
	                    });
	                });
	            });
	</script>
<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>

The problem is that your using Mootools and jQuery which both take advantage of the $ variable, to release jQuery from it read though the following documentation http://api.jquery.com/jQuery.noConflict/

There are details on how to handle this in post #102 of our [url=“http://www.sitepoint.com/forums/showthread.php?90644-Javascript-Usefull-Tips-amp-Tricks”]tips and techniques sticky thread.

did I get it right? seems like everything is new to me.


<script type="text/javascript">
		window.addEvent('domready', function(){
	                $('registerForm').addEvent('submit', function(e) {
	                    new Event(e).stop();
	                    var log = $('log_res').empty().addClass('ajax-loading');
	                    this.send({
	                        update: log,
	                        onComplete: function() {
	                            log.removeClass('ajax-loading');
	                        }
	                    });
	                });
	            });
	</script>
	<script>jQuery.noConflict();</script>
	<script>
	$(function() {
		$( "#datepicker" ).datepicker();
	});
	</script>

Not quite. Once you issue the noconflict command, jQuery no longer has access to the global $ argument. Instead, you have to use the jQuery object instead, and provide $ as an argument so that you can then use that from within the function.

For example:


jQuery.noConflict();
jQuery(function ($) {
    // jQuery's $ can be used in here, due to the function argument
    ...
});

I did not still get it.

<script>
jQuery.noConflict();
jQuery(function($) {
$( “#datepicker” ).datepicker();
});
</script>

Do you have a link we can use to see the code in action as i feel like there is more then just this one conflict that’s causing your resource issues.

As much as I want it, I don’t have it as of now. I tried it in other page, datepicker works, when I integrate it with mootols it doesn’t work now. I really believed that the problem that jquery and mootols can’t work at the same timee, because when I comment out the mootols, datepicker works. Below is my actual code.

<script src=“date/jquery-1.7.1.js”></script>
<script src=“date/jquery.ui.core.js”></script>
<script src=“date/jquery.ui.widget.js”></script>
<script src=“date/jquery.ui.datepicker.js”></script>
<script src=“js/jquery.min.js”></script>
<script src=“js/jquery.placeholder.js”></script>
<script type=“text/javascript” src=“js/mootools.js”></script>
<script type=“text/javascript”>
window.addEvent(‘domready’, function(){
$(‘registerForm’).addEvent(‘submit’, function(e) {
new Event(e).stop();
var log = $(‘log_res’).empty().addClass(‘ajax-loading’);
this.send({
update: log,
onComplete: function() {
log.removeClass(‘ajax-loading’);
}
});
});
});
</script>
<script>
jQuery.noConflict();
jQuery(function ($){

$(function() {
	$( "#datepicker" ).datepicker();
})
};
&lt;/script&gt;

What you have above currently won’t work as you don’t have a closing ) on };, also what you do have now is redundant as your wrapping a DOM ready function within a DOM ready function which is running 2 DOM ready events instead of one. What you posted before my previous post should be working fine regardless of whether Mootools exists in the page or not, unless we can get a demo of the demo it’s really difficult to see what the actual issue is. The only other thing i can offer is you try the following code which makes use of a custom jQuery reference.

$jq = jQuery.noConflict();

$jq(function($) {
    $( "#datepicker" ).datepicker();
});

I hope posting my entire code would help.

!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml”>
<head>
<title>New Student</title>
<meta http-equiv=“refresh” url=“stud_new.php”/>
<link rel=“stylesheet” href=“date/demos.css”>
<link rel=“stylesheet” href=“date/jquery.ui.all.css”>
<script src=“date/jquery-1.7.1.js”></script>
<script src=“date/jquery.ui.core.js”></script>
<script src=“date/jquery.ui.widget.js”></script>
<script src=“date/jquery.ui.datepicker.js”></script>
<script src=“js/jquery.min.js”></script>
<script src=“js/jquery.placeholder.js”></script>
<script type=“text/javascript” src=“js/mootools.js”></script>
<script type=“text/javascript”>
window.addEvent(‘domready’, function(){
$(‘registerForm’).addEvent(‘submit’, function(e) {
new Event(e).stop();
var log = $(‘log_res’).empty().addClass(‘ajax-loading’);
this.send({
update: log,
onComplete: function() {
log.removeClass(‘ajax-loading’);
}
});
});
});
</script>
<script>
$jq = jQuery.noConflict();
$jq(function($) {
$( “#datepicker” ).datepicker();
});
</script>
</head>
<body>
<br/>
<br/>
<br/>
<div id=“container”>
<form method=“post” id=“registerForm” action=“register.php”>

	&lt;P&gt;&lt;strong&gt;&lt;LABEL for="Id"&gt;Student ID:&lt;/LABEL&gt;&lt;/strong&gt;
    &lt;input name="Id" type="text" class="input" id="Id" value=""  placeholder= "Student ID" required setfocus/&gt;&lt;/P&gt;
    
	&lt;P&gt;&lt;strong&gt;&lt;LABEL for="FName"&gt;First name:&lt;/LABEL&gt;&lt;/strong&gt;
    &lt;input name="FName" type="text" class="input" id="FName" value="" placeholder= "First Name" required /&gt;&lt;/p&gt;
          
    &lt;p&gt;&lt;strong&gt;&lt;LABEL for="LFame"&gt;Last name:&lt;/LABEL&gt;&lt;/strong&gt;
	&lt;input name="LName" class="input" type="text" id="LName" value="" placeholder= "Last Name" required /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;strong&gt;&lt;LABEL for="Sex"&gt;Gender:&lt;/LABEL&gt;&lt;/strong&gt;
	&lt;select name = "Sex" class="input" &gt;
	&lt;option value = ""&gt;&lt;--Select--&gt;&lt;/option&gt;
	&lt;option value = "Male"&gt;Male&lt;/option&gt;
	&lt;option value = "Female"&gt;Female&lt;/option&gt;
	&lt;/select&gt;&lt;/p&gt;
	
    &lt;p&gt;&lt;strong&gt;&lt;LABEL for="Program"&gt;Program&lt;/LABEL&gt;&lt;/strong&gt;
	&lt;select name = "Program" class="input"  &gt;
	&lt;option value = ""&gt;&lt;--Select--&gt;&lt;/option&gt;
	&lt;option value = "Day"&gt;Day&lt;/option&gt;
	&lt;option value = "Evening"&gt;Evening&lt;/option&gt;
	&lt;option value = "Sunday"&gt;Sunday&lt;/option&gt;
	&lt;/select&gt;
	&lt;/p&gt;

	&lt;p&gt;&lt;strong&gt;&lt;LABEL for="Course"&gt;Course:&lt;/LABEL&gt;&lt;/strong&gt;
    &lt;input name="Course" class="input" type="text" id="Course" value=""  placeholder= "Course"/&gt;&lt;/p&gt;
		
	&lt;P&gt;&lt;strong&gt;&lt;LABEL for="Date"&gt;Date:&lt;/LABEL&gt;&lt;/strong&gt;
	&lt;input type="text" id="datepicker" class="input"  name= "Date" value = "" &gt;&lt;/P&gt;
		
	&lt;P &gt;&lt;input type="image" name="register" class="submit-btn" src="image/submit.png" alt="submit" title="submit" /&gt;
          &lt;/P&gt;
       
    
    &lt;/form&gt;
    &lt;/div&gt;
	&lt;div id="log"&gt;
	&lt;div id="log_res"&gt;
	&lt;!-- SPANNER --&gt;
	&lt;/div&gt;
	&lt;/div&gt;

</body>
</html>

Do’h :wall:, i completly missed the issue. The problem is your including your Mootools code right between the jQuery library and your jQuery code, if you simply move your jQuery code before the Mootools code but keep the noConflict references it should work fine.

Like this? still no work.

<link rel=“stylesheet” href=“date/demos.css”>
<link rel=“stylesheet” href=“date/jquery.ui.all.css”>
<script src=“date/jquery-1.7.1.js”></script>
<script src=“date/jquery.ui.core.js”></script>
<script src=“date/jquery.ui.widget.js”></script>
<script src=“date/jquery.ui.datepicker.js”></script>
<script src=“js/jquery.min.js”></script>
<script src=“js/jquery.placeholder.js”></script>
<script>
$jq = jQuery.noConflict();
$jq(function($) {
$( “#datepicker” ).datepicker();
});
</script>
<script type=“text/javascript” src=“js/mootools.js”></script>
<script type=“text/javascript”>
window.addEvent(‘domready’, function(){
$(‘registerForm’).addEvent(‘submit’, function(e) {
new Event(e).stop();
var log = $(‘log_res’).empty().addClass(‘ajax-loading’);
this.send({
update: log,
onComplete: function() {
log.removeClass(‘ajax-loading’);
}
});
});
});
</script>