Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find xy position of cell with php

Status
Not open for further replies.

6kleg

IS-IT--Management
Dec 21, 2004
24
US
I'm building a monthly calendar with cells for the days. I'm using php to get the data for a month's events from a mySql database, and then create the cells as I go, filling the cells with text corresponding to the event details, all with php.

When a record for an event that spans more than 1 day is reached, rather than putting in the cell for each day that it covers, I want to place an absolute positioned div across the days for the event, but I need to get the xy position of the cell where it would have gone if it were a single day event.

I can do that in javascript outside of php but I don't know how to do it when I'm between <?php and ?>. What is the correct way to call a javascript function from within the php code?



 
Remember PHP runs on the SERVER and Javascript runs on the CLIENT. By the time the client sees the code for your Javascript, PHP is long gone.

Also PHP doesn't have a clue to what the HTML it's generating is going to look like once the browser displays it.

You can generate Javascript from PHP, but it won't run until the browser starts displaying the page.

Ken
 
You don't call a JavaScript function from within a PHP script. JavaScript runs on the client, PHP runs on the server. Other than the fact that PHP can generate JavaScript code on the fly, the two have very little to do with one another.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Thanks kenrbnsn and sleipnir214,

I'm sure I'd heard that before but had forgotten. While you were replying to this question, I modified the php to include a call to a js function that is in the head of the page.

As the php runs and creates the cells for the calendar it gives each cell a unique id and a call to a js function with the code
Code:
[green]echo[/green] '<div><td id="day' [green].[/green] [b]$j[/b] [green].[/green]'" bgcolor=#ffffff ... </div>'[green];[/green]
[green]echo[/green] '<script>get_cell_xy("day' [green].[/green] [b]$j[/b] [green].[/green]'")</script>'[green];[/green]
where $j is the sequential number of the cell.

The function get_cell_xy runs when it is supposed to but it doesn't return the right value (I get x = -1 and y = -1). I have used this same function in other pages to return the position of a cell to place a div for a drop down menu so I know it works.

Any thoughts?


 
Not really. I was just trying to let you know that I figured out how to call the js function by generating it with the php.

Thanks.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top