...

View Full Version : use php to get style of html element



jsnewbie2
02-16-2010, 07:10 AM
Goal: Using PHP, get the location of an html tag and store in mysql database

Background: Based on a mouse click, I use css style.top and style.left to set the location of the html tag using javascript. I am using php to do the database calls.

Can I get the style (e.g., style.top, style.left) of an html tag using PHP?

[CODE]
//javascript code when I create the html tag
//posx, posy are from the mouse click
var newDiv= document.createElement("img");
newDiv.style.top= (posy -10) +'px';
newDiv.style.left= (posx -6) +'px';
...
[CODE]

bdl
02-16-2010, 07:22 AM
I'm not certain what you're getting at. PHP is a server-side language, it doesn't operate in the browser. On the other hand, JavaScript (which you've shown an example of) does operate on the client, in the browser.

Having said all that, if you were to use an event handler to call an Ajax-y function to use PHP to store data, that's a whole different ball of wax. But it's no different than handing off some value to a PHP script and storing it in a database. There's no magic there, no "browser trickery" to get PHP to interact with the HTML document.

Len Whistler
02-16-2010, 07:41 AM
I gather you want to enter the JavaScript newDiv variable into a MySQL database using PHP?


var newDiv= document.createElement("img");
Or perhaps this value:

newDiv.style.top= (posy -10) +'px';


The only way I know is to write the Javascript variables to a cookie with Javascript and use PHP to retrieve the same cookie and enter into a database.


-------------------

SKDevelopment
02-16-2010, 09:36 AM
The only way I know is to write the Javascript variables to a cookie with Javascript and use PHP to retrieve the same cookie and enter into a database.
I would not use a cookie for it. I would use AJAX. And to simplify the task and to make the code more cross-browser compatible, you could use some known JavaScript library for it. E.g. you could use jQuery.

jsnewbie2
02-16-2010, 04:28 PM
Ok let me back up. Is it possible to get a mouseclick location to php? Let me say that I'm a php newbie too. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum