Passing PHP Variable to Javascript Function, Can't Open a Window in a Javascript function with a Parameter Pass |
Passing PHP Variable to Javascript Function, Can't Open a Window in a Javascript function with a Parameter Pass |
Jonah |
Feb 7 2017, 10:51 AM
Post
#1
|
Group: Members Posts: 6 Joined: 7-February 17 Member No.: 26,301 |
I apologize in advance if this has been answered but I've tried all the suggestions I've found but still no joy.
In PHP, I have pulled data from a database and displayed it in a table inserting a button in the first cell of each row titled with a PHP variable. Clicking that button should call a javascript function that opens a child window to display details of data on that row. Everything works fine except for the fact that I cannot pass a PHP variable to the javascript function. Passing hard-coded integer or string data appears to work. Here is the java script: <script language='javascript' type='text/javascript'> function myPopup(id) { window.open('flowdetail.php?uuid='+id, 'myWindow','status = 1, height = 300, width = 300, resizable = 0' ) }; </script> Here is the code in the target window (echos passed value just for testing): <?php // content="text/plain; charset=utf-8" $uuid = $_GET['uuid']; echo $uuid; ?> Here is the PHP that populates the table and offers the button: echo "><td><input name='found_one' type=button "; echo "onClick=myPopup($uuid); value='$ctags[$z]'/>" . " " . $results['location'] . "</td><td style='word-wrap: break-word'>" . substr($results['description'],0,140) . "</td><td>" . $cpname . "</td>"; I've been hacking at this for days so any help would be greatly appreciated! |
CharlesEF |
Feb 9 2017, 04:34 PM
Post
#2
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Also, because of this bad HTML button code:
CODE echo "><td><input name='found_one' type=button "; When the OP wraps the $uuid value in quotes then the button will not fire the function because the button HTML is invalid.echo "onClick=myPopup($uuid); value='$ctags[$z]'/>" . EDIT: Funny thing, even with the bad HTML button code, if the $uuid value is numeric and NOT wrapped in quotes then the button will fire the function. The problem only shows up when the $uuid value is wrapped in quotes (single or double, it doesn't matter). This post has been edited by CharlesEF: Feb 9 2017, 04:42 PM |
Christian J |
Feb 9 2017, 05:10 PM
Post
#3
|
. Group: WDG Moderators Posts: 9,661 Joined: 10-August 06 Member No.: 7 |
The problem only shows up when the $uuid value is wrapped in quotes (single or double, it doesn't matter). Or if the $uuid value is a string, and it's not quoted in the JS function call. This makes me believe it is a string, otherwise the JS should have worked one way or another. |
CharlesEF |
Feb 9 2017, 06:17 PM
Post
#4
|
Programming Fanatic Group: Members Posts: 1,981 Joined: 27-April 13 From: Edinburg, Texas Member No.: 19,088 |
Or if the $uuid value is a string, and it's not quoted in the JS function call. This makes me believe it is a string, otherwise the JS should have worked one way or another. $uuid may be a string, as you suggest, but until the OP fixes the HTML button code, the function will never fire. This post has been edited by CharlesEF: Feb 9 2017, 06:18 PM |
Lo-Fi Version | Time is now: 27th April 2024 - 02:07 AM |