Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2010, 06:10 AM   PM User | #1
jsnewbie2
New Coder

 
Join Date: Feb 2010
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
jsnewbie2 is an unknown quantity at this point
use php to get style of html element

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]
jsnewbie2 is offline   Reply With Quote
Old 02-16-2010, 06:22 AM   PM User | #2
bdl
Regular Coder

 
Join Date: Apr 2007
Location: Camarillo, CA US
Posts: 590
Thanks: 4
Thanked 83 Times in 82 Posts
bdl is an unknown quantity at this point
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.
bdl is offline   Reply With Quote
Old 02-16-2010, 06:41 AM   PM User | #3
Len Whistler
Senior Coder

 
Len Whistler's Avatar
 
Join Date: Jul 2002
Location: Vancouver, BC Canada
Posts: 1,323
Thanks: 26
Thanked 100 Times in 100 Posts
Len Whistler is on a distinguished road
I gather you want to enter the JavaScript newDiv variable into a MySQL database using PHP?

Code:
var newDiv= document.createElement("img");
Or perhaps this value:
Code:
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.


-------------------
__________________
Leonard Whistler

Last edited by Len Whistler; 02-16-2010 at 06:43 AM..
Len Whistler is offline   Reply With Quote
Old 02-16-2010, 08:36 AM   PM User | #4
SKDevelopment
Regular Coder

 
Join Date: Mar 2006
Posts: 238
Thanks: 3
Thanked 37 Times in 37 Posts
SKDevelopment has a little shameless behaviour in the past
Quote:
Originally Posted by Len Whistler View Post
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.
__________________
PHP Programmer
SKDevelopment is offline   Reply With Quote
Old 02-16-2010, 03:28 PM   PM User | #5
jsnewbie2
New Coder

 
Join Date: Feb 2010
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
jsnewbie2 is an unknown quantity at this point
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!
jsnewbie2 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 09:52 AM.


Advertisement
Log in to turn off these ads.