How to segregate the whole code..please check - php

Hi iam using this code here http://jsfiddle.net/bryanjamesross/pyNJ9/ I segregated the whole code in one page..means like the javascript under this tags
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
</script>
and the css code under
<script type="text/css">
</script>
and used html code in html tags..but i am getting the textboxes also instead of single login href link.
<html>
<head>
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript">
$('a.loginlink').click(function(e) {
$('#loginform').dialog('open');
e.preventDefault();
return false;
});
$('#loginform').dialog({
autoOpen: false,
modal: true,
resizable: false,
draggable: false
});
</script>
</head>
<body>
Log In
<div id="loginform">
<form action="/login" method="post">
<table>
<tr>
<td>User Name:</td>
<td>
<input name="username" type="text" />
</td>
</tr>
<tr>
<td>Password:</td>
<td>
<input name="password" type="password" />
</td>
</tr>
<tr>
<td colspan="2" style="text-align:center;">
<input type="submit" value="Login" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>

You need to include jQuery UI as well.
The files the jsfiddle, you posted, uses are CDN hosted script and CDN hosted stylesheet
so change your code to
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/jquery-ui.min.js"></script>
<script type="text/javascript">
</script>
and add in the head of your page
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.16/themes/cupertino/jquery-ui.css" />
UPDATE
Important You need to wrap the code in $(function(){ ... }) so that it runs after the DOM is loaded.
$(function(){
$('a.loginlink').click(function(e) {
$('#loginform').dialog('open');
e.preventDefault();
return false;
});
$('#loginform').dialog({
autoOpen: false,
modal: true,
resizable: false,
draggable: false
});
});
and to be sure that your jquery version is compatible with jquery UI version use
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
instead of
<script type="text/javascript" src="jquery.js"></script>
Full code at http://jsfiddle.net/gaby/k6KjS/

Related

jQuery autocomplete fetch from function not a file

I want to fetch the json data from function and not file.
How can i change the autocomplete.php to a PHPfunction?
My code:
<html>
<head>
<link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
<script>
$(function() {
$( "#skills" ).autocomplete({
source: 'autocomplete.php'
});
});
</script>
</head>
<body>
<div class="ui-widget">
<label for="skills">Skills: </label>
<input id="skills">
</div>
</body>
</html>
Add get or post parameter to your ajax, for example action=func1 and in your php file make a switch and in the case of action is "func1" just call func1().

The usage of TinyMCE 4.1.4 in php page

I'm trying to use TinyMCE 4.1.4 in my php page but I didn't succeed, I did include the path of TinyMCE but when I execute the script it gives me simple text area, I don't know what's the problem.
<html>
<head>
<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea"
});
</script>
</head>
<body>
<form method="post">
<textarea ></textarea>
</form>
</body>
</html>
Works fine here jsFiddle Demo
Try to include your code inside ready function before that include jQuery library as well so your full code should be :
<script src="http://code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript" src="http://tinymce.cachefly.net/4.1/tinymce.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
tinymce.init({
selector: "textarea"
});
});
</script>
</head>
<body>
<form method="post">
<textarea ></textarea>
</form>
</body>
</html>
It's because you're doing all the JS before the DOM has fully loaded.
<body>
<form method="post">
<textarea ></textarea>
</form>
<script type="text/javascript" src="js/tinymce/tinymce.min.js"></script>
<script type="text/javascript">
tinymce.init({
selector: "textarea"
});
</script>
</body>
</html>

autocomplete is not a function error

I'm working in twitter Bootstrap with PHP. I make a search form and apply autocomplete to search field but its not working, though its working fine when I test it outside the my working directory.
Here are my jquery files:
<script type="text/javascript"
src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
<script type="text/javascript" src="assets/js/jquery.autocomplete.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#term").autocomplete({
source:'action.php',
minLength:1
});
});
</script>
<script src="assets/js/bootstrap-datepicker.js"></script>
<script type="text/javascript">
$("#datepicker").datepicker();
</script>
<script type="text/javascript">
$("#datepicker1").datepicker();
</script>
<script type="text/javascript">
$("#datepicker2").datepicker();
</script>
<script type="text/javascript">
$("#datepicker3").datepicker();
</script>
<script type="text/javascript">
$("#datepicker4").datepicker();
</script>
and here is my search field in the form:
<input type="text" class="span3 search-query" id="term" name="term" placeholder="search by customer-name, company-name and location" autocomplete="off">
Here is the css for autocomplete:
<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8/themes/base/jquery-ui.css" />
Here is my action.php file:
<?php
include("config.php");
$term=$_GET["term"];
$query=mysql_query("SELECT * FROM customers where name like '%".$term."%'");
$json=array();
while($customer=mysql_fetch_array($query)){
$json[]=array(
'value'=> $customer["name"],
'label'=>$customer["name"],
);
}
echo json_encode($json);
?>
On Google chrome press F12 before loading the page and see in the 'Network' tab if the jquery.autocomplete.js is loading. If its not, Please use the correct relative path for it.

PHP: DatePicker/Calendar not displaying

I have two forms I named it main.php and sample.php.... For main.php I have a calendar/datepicker and its working. But then when I proceed to the next page or to the sample.php the calendar/datepicker its not displaying anymore... I just copy the codes from main.php to sample.php
Here's my code for main.php:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script>
$(function() {
$( "#datepickerfrom" ).datepicker();
});
$(function() {
$( "#datepickerto" ).datepicker();
});
</script>
From: <input type="text" id="datepickerfrom"name="from"> To: <input type="text" id="datepickerto"name="to">
And For sample.php:
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<link rel="stylesheet" href="/resources/demos/style.css" />
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function () {
$('.checkall').on('click', function () {
$(this).closest('fieldset').find(':checkbox').prop('checked', this.checked);
});
});
$(function() {
$( "#datepickerfrom" ).datepicker();
});
$(function() {
$( "#datepickerto" ).datepicker();
});
</script>
From: <input type="text" id="datepickerfrom"name="from"> To: <input type="text" id="datepickerto"name="to">
<?php
echo "<div><input type='checkbox' class='checkall'> Check all</div>";
?>
But in the sample.php I added a code for checkbox all where I also use a script...
Thanks/.
Thats because you are calling jquery two times in sample.php. Either remove
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
or
<script src="http://code.jquery.com/jquery-latest.js"></script>
P.S jquery-ui.js should come after jquery
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
You need those lines on sample.php, tried it, it worked.

datepicker codeigniter 2.2 problem

hi im trying to integrate a jquery datepicker to my codeigniter project.. the problem is that i cant get it to work .. my source code came from http://view.jquery.com/tags/ui/latest/demos/functional/#ui.datepicker
ok heres my code:
view:
<srcipt>
$("#formatted").datepicker({
dateFormat: $.datepicker.ISO_8601,
showOn: "both",
buttonImage: "templates/images/calendar.gif",
buttonImageOnly: true
});
</script>
<form action="add" method="post" class="form label-inline uniform" />
<input type="text" size="30" value="" id="formatted"/>
<input type="submit" class="btn btn-grey" value="Add User"/>
</form>
<script src="/assets/js/jquery/jquery-1.5.2.min.js"></script>
EDIT
i already added all the js sources but its still not working
<script src="/assets/js/jquery/jquery-1.5.2.min.js"></script>
<script src="/assets/js/jquery/jquery-ui-1.8.12.custom.min.js"></script>
<script src="/assets/js/misc/excanvas.min.js"></script>
<script src="/assets/js/jquery/facebox.js"></script>
<script src="/assets/js/jquery/jquery.visualize.js"></script>
<script src="/assets/js/jquery/jquery.dataTables.min.js"></script>
<script src="/assets/js/jquery/jquery.tablesorter.min.js"></script>
<script src="/assets/js/jquery/jquery.uniform.min.js"></script>
<script src="/assets/js/jquery/jquery.placeholder.min.js"></script>
<script src="/assets/js/widgets.js"></script>
<script src="/assets/js/dashboard.js"></script>
EDIT
created a sample view page for datepicker.. still not working even the link for the image is not working.
<html>
<head>
<script src="/assets/js/jquery/jquery-1.5.2.min.js"></script>
<script src="/assets/js/jquery/jquery-ui-1.8.12.custom.min.js"></script>
<script src="/assets/js/misc/excanvas.min.js"></script>
<script src="/assets/js/jquery/facebox.js"></script>
<script src="/assets/js/jquery/jquery.visualize.js"></script>
<script src="/assets/js/jquery/jquery.dataTables.min.js"></script>
<script src="/assets/js/jquery/jquery.tablesorter.min.js"></script>
<script src="/assets/js/jquery/jquery.uniform.min.js"></script>
<script src="/assets/js/jquery/jquery.placeholder.min.js"></script>
<script src="/assets/js/widgets.js"></script>
<script src="/assets/js/dashboard.js"></script>
</head>
<body>
<script>
$("#formatted").datepicker({
dateFormat: $.datepicker.ISO_8601,
showOn: "both",
buttonImage: "http://pgoadmin.com/assets/images/calendar.gif",
buttonImageOnly: true
});
</script>
<form>
<input type="text" size="30" value="" id="formatted"/>
</form>
</body>
</html>
You need to load in jQuery UI to use the date picker
https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.13/jquery-ui.js
Dont forget the images and CSS as well:
http://jqueryui.com/download
You need to include jquery before you start using it. Try moving the JS code below the jquery tag.
And as Wes says, you need to include jquery UI datepicker component as well.
Also, and this maybe a typo, your tag says "sricpt" instead of "script".
and don't forget to add base_url(); to your js paths
e.g.
<script src="<?php echo base_url(); ?>assets/js/dashboard.js"></script>

Categories