Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Linux, Apache, MySQL, PHP
  4. PHP & JavaScript integration

PHP & JavaScript integration

Scheduled Pinned Locked Moved Linux, Apache, MySQL, PHP
helpjavascriptphpquestion
5 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MacRaider4
    wrote on last edited by
    #1

    I think this belongs better in the forum as I believe the problem to be on the PHP side. What I'm doing is creating a table dynamically that has some JavaScript function calls in it (well I'm trying to). The page is displaying ok in Chrome and Firefox but IE is complaining about it and not displaying at all. However in Chrome and Firefox it's not "working" just displaying right. this is the code I'm trying to use...

    $display_string .= "<td><a href='javascript:choice('".$row .$col ."')'><img src='images/o.jpg' border=0 height=100 width=100 name='" .$row .$col ."' alt='Open'></a></td>";

    When you hover over one of the cells on the loaded page you see javascript:choice(. It should read something like javascript:choice(A3) If I do an inspect element with chrome I get

    Open

    so it appears the issue is in the creation of the javascript call? Thanks in advance!!

    G 1 Reply Last reply
    0
    • M MacRaider4

      I think this belongs better in the forum as I believe the problem to be on the PHP side. What I'm doing is creating a table dynamically that has some JavaScript function calls in it (well I'm trying to). The page is displaying ok in Chrome and Firefox but IE is complaining about it and not displaying at all. However in Chrome and Firefox it's not "working" just displaying right. this is the code I'm trying to use...

      $display_string .= "<td><a href='javascript:choice('".$row .$col ."')'><img src='images/o.jpg' border=0 height=100 width=100 name='" .$row .$col ."' alt='Open'></a></td>";

      When you hover over one of the cells on the loaded page you see javascript:choice(. It should read something like javascript:choice(A3) If I do an inspect element with chrome I get

      Open

      so it appears the issue is in the creation of the javascript call? Thanks in advance!!

      G Offline
      G Offline
      Graham Breach
      wrote on last edited by
      #2

      You need to properly match up your quotes - you used a single quote for href= and then the closing quote was just inside the javascript function. Try this:

      $display_string .= "<td><a href=\"javascript:choice('{$row}{$col}')\"><img src='images/o.jpg' border=0 height=100 width=100 name='{$row}{$col}' alt='Open'></a></td>";

      I've replaced the outer single quotes with escaped double quotes. I've also put the $row and $col variables into the string so that the '.' operator is not required, but that's just my personal preference.

      M 1 Reply Last reply
      0
      • G Graham Breach

        You need to properly match up your quotes - you used a single quote for href= and then the closing quote was just inside the javascript function. Try this:

        $display_string .= "<td><a href=\"javascript:choice('{$row}{$col}')\"><img src='images/o.jpg' border=0 height=100 width=100 name='{$row}{$col}' alt='Open'></a></td>";

        I've replaced the outer single quotes with escaped double quotes. I've also put the $row and $col variables into the string so that the '.' operator is not required, but that's just my personal preference.

        M Offline
        M Offline
        MacRaider4
        wrote on last edited by
        #3

        Now I see what I did wrong in my other version, I forgot the escape character... the joys of learning new languages. Thanks, it seems to be working now. Putting a variable inside {} adds it to a string? I didn't know that. :thumbsup: I really appreciate the help!!

        G 1 Reply Last reply
        0
        • M MacRaider4

          Now I see what I did wrong in my other version, I forgot the escape character... the joys of learning new languages. Thanks, it seems to be working now. Putting a variable inside {} adds it to a string? I didn't know that. :thumbsup: I really appreciate the help!!

          G Offline
          G Offline
          Graham Breach
          wrote on last edited by
          #4

          Quote:

          Putting a variable inside {} adds it to a string? I didn't know that.

          No, not exactly - using a variable beginning with '$' inside a double-quoted string is enough, the {} around the variable is useful for keeping it separated in the middle of content. Here is the documentation that will explain it better than I can: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex[^]

          M 1 Reply Last reply
          0
          • G Graham Breach

            Quote:

            Putting a variable inside {} adds it to a string? I didn't know that.

            No, not exactly - using a variable beginning with '$' inside a double-quoted string is enough, the {} around the variable is useful for keeping it separated in the middle of content. Here is the documentation that will explain it better than I can: http://www.php.net/manual/en/language.types.string.php#language.types.string.parsing.complex[^]

            M Offline
            M Offline
            MacRaider4
            wrote on last edited by
            #5

            Thanks for the link, that really helps

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups