SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript variable in php function?

    Code JavaScript:
    pDOB2.innerHTML = '<?=XDOBDay(' + xCount + ');?> <?=XDOBMonth(' + xCount + ');?> <?=XDOBYear(' + xCount + ');?>';

    pDOB2 is then appended as a child to another element.

    The problem is, at the moment instead of parsing xCount, a variable which is an auto-incrementing number, it is just displaying + xCount +, which, of course, is expected. However, I don't know how to parse xCount in that innerHTML call.

    (I tried searching the web for this kind of stuff but came to no particular solution).

  2. #2
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,119
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    Hmm, I think you may be a little confused.
    Javascript obviously cannot understand PHP,
    So you're PHP code needs to generate straight JS and HTML

    Are you confused about the javascript syntax for what you are wanting or the PHP syntax?

  3. #3
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know that the code is very wrong, I just wrote it that way to show what I want to do. I want to pass the JS var xCount into a PHP function. I realise that JS is client side, but figured there might be a way to do this without say, refreshing the page - perhaps using AJAX or something?

    If it isn't possible easily, then I do have a workaround.

  4. #4
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,119
    Mentioned
    28 Post(s)
    Tagged
    2 Thread(s)
    You could send information to a PHP script from javascript using Ajax, but i'm guessing there's a better to achieve what you want that doesn't involve javascript. But I really don't know what you are trying to achieve.

  5. #5
    SitePoint Evangelist N9ne's Avatar
    Join Date
    Aug 2002
    Location
    UK
    Posts
    596
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah I thought so, but didn't really know where to start. This was more of a speculative thread... I do indeed have a more PHP-oriented workaround. Essentially I have this very complex form to which I can also add/remove chunks to (emulations of a part which already exists) on the fly via a button. I was attempting to simplify the processing nightmare by assigning IDs in such a way but I have since worked out a good way to do things using PHP.

    Thanks anyway


Bookmarks

Posting Permissions

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