Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts

    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]

  • #2
    bdl
    bdl is offline
    Regular Coder
    Join Date
    Apr 2007
    Location
    Camarillo, CA US
    Posts
    590
    Thanks
    4
    Thanked 83 Times in 82 Posts
    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.

  • #3
    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
    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.


    -------------------
    Last edited by Len Whistler; 02-16-2010 at 06:43 AM.
    Leonard Whistler

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    238
    Thanks
    3
    Thanked 37 Times in 37 Posts
    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.

  • #5
    New Coder
    Join Date
    Feb 2010
    Posts
    15
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •