Jump to content

Recommended Posts

I'm not a very good JS developer but I'm muddling my way through creating a nice interface for my program with AJAX and jQueryUI. The AJAX part I have working fine, but I can't seem to get jQueryUI working.

 

I read some of the intros and thought it was pretty simple. I have this in my header:

 

<link type="text/css" href="http://example.com/myfolder/application/assets/css/redmond/jquery-ui-1.8.9.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>

 

I have verified that all those links work (i changed the actual path to my project to example.com/myfolder but the real one works).

 

In a test page I put:

	<script>
$(function() {
	$( "#datepicker" ).datepicker({
		changeMonth: true,
		changeYear: true
	});
});
</script>



<div class="demo">

<p>Date: <input type="text" id="datepicker"></p>

</div><!-- End demo -->

 

I copied and pasted that from a demo on the jQueryUI website. On their website, when you give focus to the input box, you get a calendar. On my test, nothing at all happens.

 

What gives? It's probably something obvious since I'm so new to jQueryUI  :D

 

Link to comment
https://forums.phpfreaks.com/topic/225237-jquery-ui-not-working/
Share on other sites

Firebug reports no JavaScript errors other than:

Unexpected token in attribute selector: '!'.

 

I googled that and it's a known issue, or rather a known non-issue. Apparently it doesn't cause problems.

 

There are, however, a bunch of CSS errors. I don't see a way to copy and paste them all at once in Firebug, though. Mostly they seem to be stuff like this:

 

Unknown property 'border-top-left-radius'.  Declaration dropped.

 

Which is strange, but even if there are CSS errors then at least SOMETHING should display, right?

 

I'm using firefox 3.6.13

I just ran your code in firefox and it worked fine.  Do you have other code that could be affecting it?

 

Actually yeah I think that might be the problem. I put this in a completely separate file from my project and it worked. After some tinkering it looks like the Prototype JS framework I'm using conflicts with it. If I remove it then the calendar pops up fine. Are these two known to conflict or something?

 

Truth be told I don't even know what Prototype does, I just use it because it's required by the CodeIgniter AJAX library I'm using. If I remove the link to prototype.js then the jQueryUI stuff works, but my AJAX call do not  :(

After some tinkering it looks like the Prototype JS framework I'm using conflicts with it. If I remove it then the calendar pops up fine. Are these two known to conflict or something?

 

Yes there will be a conflict when using 2 separate JS libraries.  Read this link:

http://docs.jquery.com/Using_jQuery_with_Other_Libraries

 

Basically you will have to call jQuery.noConflict which will override the '$' and allow prototype to use it.  For JQuery you will have to use jQuery(...).

Aha that explains it!

 

I assume I can just change my header to something like this:

<link type="text/css" href="http://example.com/myfolder/application/assets/css/redmond/jquery-ui-1.8.9.custom.css" rel="Stylesheet" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js"></script>
<script>jQuery.noConflict();</script>

 

And then change $ to jQuery everywhere I try to use it? That header is common to almost all of my pages, the jQuery stuff is pieced together from other sources and dumped into the page (mostly pieces of forms retrieved with AJAX).

Aha that explains it!

 

I assume I can just change my header to something like this:



jQuery.noConflict();

 

And then change $ to jQuery everywhere I try to use it? That header is common to almost all of my pages, the jQuery stuff is pieced together from other sources and dumped into the page (mostly pieces of forms retrieved with AJAX).

 

$ gets changed to jQuery everywhere you're using JQuery.  Prototype shouldn't need any changed b/c it is already using.

 

The jQuery.noConflict() just gives up the '$' (which is actually an alias for jQuery) and allows the other libraries to use it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.