SitePoint Sponsor

User Tag List

Results 1 to 11 of 11
  1. #1
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question jquery novice to ninja: i need help index.php

    i use php but i'm a total novice to juery,i just bought the book and i can't get past my first code, tried adding jquery script into my php code something like this


    index.php

    <html>
    <head>

    <style>
    #cd {
    width: 200px; height: 50px;
    margin: auto; padding: 5px;
    font-family: Arial; font-size: 18pt;
    }
    </style>

    <script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
    <script type='text/javascript' src='script.js'></script>


    <script language="javascript"
    <src="localhost/today2/countdown.php"></script></head>

    <?php


    echo "today's date is";
    echo date ('l, F dS Y' );

    ?>
    <body>
    <form method="get" action="http://www.google.com/search" target="_blank">

    <div style="border:1px solid black;padding:4px;width:20em;">
    <table border="0" cellpadding="0">
    <tr><td>
    <input type="text" name="q" size="25"
    maxlength="255" value="" />
    <input type="submit" value="Google Search" /></td></tr>
    <tr><td align="center" style="font-size:75%">
    <input type="checkbox" name="sitesearch"
    value="yahoo.com" checked /> only search this site<br />
    </td></tr></table>
    </div>

    </form>






    $(document).ready(function() {
    alert('hola!');
    });


    </body>
    </html>

    when i run it, it returns $(document).ready(function() {
    alert('hola!');
    });

    on my page. what am i doing wrong?

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,588
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    Hi dovesar. Welcome to SitePoint.

    I notice a few errors here:

    Code:
    <script language="javascript"
    <src="localhost/today2/countdown.php"></script
    That red < should not be there. But there should be a closing > at the very end.

    Lower down, this code

    Code:
    $(document).ready(function() {
     alert('hola!');
    });
    Should be wrapper in <script> tags. E.g.

    Code:
    <script type="text/javascript">
    $(document).ready(function() {
     alert('hola!');
    });
    </script>
    Not sure if that will fix everything for you, but it's a start.

  3. #3
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you ralph,
    sorry about the mixed up code earlier,
    i actually have something like this in index.php




    <?php
    echo date (' I, F ds Y');
    ?>
    <html>

    <head>
    <script type='text/javascript' src="jquery/1.6.2/jquery.min.js"></script>
    <script type='text/javascript' src='script.js'></script>
    </head>



    $(document).ready(function() {
    alert('hola!');
    });


    <body>

    </body>

    </html>


    the page just return this line of code

    $(document).ready(function() {
    alert('hola!');
    });


    i am testing locally using WAMP and IE9, and jquery 1.6.2

  4. #4
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    23,588
    Mentioned
    411 Post(s)
    Tagged
    6 Thread(s)
    As I said, you can't have this on its own in the HTML:

    Code:
    $(document).ready(function() {
    alert('hola!');
    });
    It must be wrapped in <script> tags, as I showed above.

  5. #5
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    thank you

  6. #6
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    am not getting any alert/message, am i still doing something wrong? though no more error,
    this guy alert('hola'); is not executing

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2011
    Location
    Dartmouth, MA, USA
    Posts
    49
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You might want to try putting the function inside script tags just before the closing tag of the head. I don't think code outside the head or body will run, though I've never tried. And I think you need to have functions defined inside $(document).ready() to be in the head in order to run anyway.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    The script code must be inside script tags, and those script tags must be inside either the head or the body section of the page.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i have something like
    <head>
    <script type="text/javascript">
    $(document).ready(function() {
    alert("hola");
    });

    </script>
    </head>

  10. #10
    SitePoint Wizard bronze trophy chris.upjohn's Avatar
    Join Date
    Apr 2010
    Location
    Melbourne, AU
    Posts
    2,183
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    That should work fine now
    Blog/Portfolio | Evolution Xtreme | DFG Design | DFG Hosting | CSS-Tricks | Stack Overflow | Paul Irish
    Having lame problems with your code? Let us help by using a jsFiddle

  11. #11
    SitePoint Member
    Join Date
    Jul 2011
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank you all


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
  •