Hi,
I was wondering if anyone could give me a hand with this. Is there anything special I need to know about using JavaScript inside of PHP?

I am making a calendar that I want to display a red dot on dates that have an entry in the database. My code for the particular dates is like this:

<td>
<script>
<!--
redBall(80102);
-->
</script>
</td>

And then redBall is defined at the top of the page (which has an extension of .php) something like this:

<?php
function redBall($datePick) {
$stuff = mysql_query("SELECT * FROM $month where Date = $dayPick");
$someNum=mysql_numrows($stuff);
if ($someNum > 0) {
echo("<br><img src='redBall.gif' border='0'>");
}
}
?>

I have not included all of the code, obviously, I have just pared it down to what is giving me the problem. This seems like a simple function so I just figured my mistakes are in using JavaScript inside the PHP page?

Any help is greatly appreciated.
Thanks!
George

    you can use php call a javascript function. but it seems you are using javascript to call a php function. i am not sure if it can work. or that is the problem?

      <script>
      <!--
      <?php
      redBall(80102);
      ?>
      -->
      </script>
      </td>

        'help' is right. You cannot call a server-side function from a client-side script. The users browser has NO knowledge that the page has nay php at all. instead of using the <script/> tag do what 'help' said and just call the function as you would normally within the <?php ?> tags.

          It's not possible to have javascript call a PHP function because the PHP code is executed on the server BEFORE the page is sent to your browser where your javascript code is executed.

            thanks, I'm working on it now!

              I feel silly now, but thank you very much.

                Write a Reply...