Results 1 to 2 of 2

Thread: how to add javascript in php page?

  1. #1
    Join Date
    Nov 2014
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to add javascript in php page?

    what is the right way too add script to php page. i have the code with html and it work fin
    Code:
    <!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

    Code:
    <?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'>
        ";
    
    ?>

  2. #2
    Join Date
    Jul 2008
    Location
    Derbyshire, UK
    Posts
    3,033
    Thanks
    25
    Thanked 599 Times in 575 Posts
    Blog Entries
    40

    Default

    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;
    Code:
    <!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.
    Focus on Function Web Design
    Fast Edit (A flat file, PHP web page editor & CMS. Small, FREE, no database!) | Fast Edit BE (Snippet Manager) (Web content editor for multiple editable regions!) | Fast Apps

Similar Threads

  1. Can you use javascript w/in an xml page?
    By Cyn in forum JavaScript
    Replies: 6
    Last Post: 04-23-2010, 12:54 AM
  2. Replies: 0
    Last Post: 04-04-2009, 07:48 AM
  3. Possible to dynamically insert a page and run javascript contained on that page?
    By snapple_pitchcock in forum Dynamic Drive scripts help
    Replies: 6
    Last Post: 01-18-2009, 07:34 AM
  4. Javascript Page Error?
    By kwertyuk in forum JavaScript
    Replies: 2
    Last Post: 10-15-2008, 11:32 AM
  5. need help with Javascript On Wen Page
    By virgorickie in forum JavaScript
    Replies: 9
    Last Post: 11-12-2005, 03:05 PM

Bookmarks

Posting Permissions

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