Log in

View Full Version : how to add javascript in php page?



ebrahim1
11-01-2014, 07:40 PM
what is the right way too add script to php page. i have the code with html and it work fin

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="./js/jquery.calendars.picker.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="./js/jquery.plugin.js"></script>
<script src="./js/jquery.calendars.js"></script>
<script src="./js/jquery.calendars.plus.js"></script>
<script src="./js/jquery.calendars.picker.js"></script>
<!--<script src="jquery.calendars.picker.ext.js"></script><!-- Include for ThemeRoller styling -->
<script src="./js/jquery.calendars.ummalqura.js"></script>
<script>
$(function() {

var calendar = $.calendars.instance('ummalqura');
$('#popupDatepicker').calendarsPicker({calendar: calendar});

});

function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
</head>
<body>

<p><input type="text" id="popupDatepicker"></p>

</body>
</html>

it is very important for me to work without html tag.

this is the Source link: http://keith-wood.name/calendarspicker.html

underneath my best try but still not work :(


<?php
echo('<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>');
echo('<script src="./js/jquery.plugin.js"></script>');
echo('<script src="./js/jquery.calendars.js"></script>');
echo('<script src="./js/jquery.calendars.plus.js"></script>');
echo('<script src="./js/jquery.calendars.picker.js"></script>');
echo('<script src="./js/jquery.calendars.ummalqura.js"></script>');
?>
<?php echo "<script type=\"text/javascript\">
function javascript{
<script>
$(function() {

var calendar = $.calendars.instance('ummalqura');
$('#popupDatepicker').calendarsPicker({calendar: calendar});

});

function showDate(date) {
alert('The date chosen is ' + date);
}
}
</script>"
?>

<?php

echo "
<input id='popupDatepicker' name='date' type='text'>
";

?>

Beverleyh
11-02-2014, 08:39 AM
With the example given, you don't actually need to enclose html in php echos - you can just change the file extension to .php

So just use the first block of code, without the echos inside, and change the file extension to .php. There's no php inside at this stage but the page will display normally (when served via a php enabled server in a web browser) regardless.

When you do come to insert php code into the html, it's fine to do this;

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<link rel="stylesheet" href="./js/jquery.calendars.picker.css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="./js/jquery.plugin.js"></script>
<script src="./js/jquery.calendars.js"></script>
<script src="./js/jquery.calendars.plus.js"></script>
<script src="./js/jquery.calendars.picker.js"></script>
<!--<script src="jquery.calendars.picker.ext.js"></script><!-- Include for ThemeRoller styling -->
<script src="./js/jquery.calendars.ummalqura.js"></script>
<script>
$(function() {

var calendar = $.calendars.instance('ummalqura');
$('#popupDatepicker').calendarsPicker({calendar: calendar});

});

function showDate(date) {
alert('The date chosen is ' + date);
}
</script>
</head>
<body>

<p><?php echo "hello";?></p>

<p><input type="text" id="popupDatepicker"></p>

</body>
</html>And only use php where it needs to be.