PHP & JavaScript integration
-
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
so it appears the issue is in the creation of the javascript call? Thanks in advance!!
-
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
so it appears the issue is in the creation of the javascript call? Thanks in advance!!
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.
-
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.
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!!
-
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!!
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[^]
-
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[^]
Thanks for the link, that really helps