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?

Hi dovesar. Welcome to SitePoint. :slight_smile:

I notice a few errors here:

<script language="javascript"
[COLOR="Red"]<[/COLOR]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

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

Should be wrapper in <script> tags. E.g.

<script type="text/javascript">
$(document).ready(function() {
 alert('hola!');
});
</script>

Not sure if that will fix everything for you, but it’s a start. :slight_smile:

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

As I said, you can’t have this on its own in the HTML:

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

It must be wrapped in <script> tags, as I showed above.

thank you

am not getting any alert/message, am i still doing something wrong? though no more error,
this guy alert(‘hola’); is not executing

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.

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.

i have something like
<head>
<script type=“text/javascript”>
$(document).ready(function() {
alert(“hola”);
});

</script>
</head>

That should work fine now

thank you all