The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Passing PHP Variable to Javascript Function, Can't Open a Window in a Javascript function with a Parameter Pass
Jonah
post 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!
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
 
Reply to this topicStart new topic
Replies
CharlesEF
post 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 ";
echo "onClick=myPopup($uuid); value='$ctags[$z]'/>" .
When the OP wraps the $uuid value in quotes then the button will not fire the function because the button HTML is invalid.

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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
Christian J
post Feb 9 2017, 05:10 PM
Post #3


.
********

Group: WDG Moderators
Posts: 9,630
Joined: 10-August 06
Member No.: 7



QUOTE(CharlesEF @ Feb 9 2017, 10:34 PM) *

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.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post
CharlesEF
post 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



QUOTE(Christian J @ Feb 9 2017, 04:10 PM) *

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.
Yes, that goes without saying.

$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
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic
Jonah   Passing PHP Variable to Javascript Function   Feb 7 2017, 10:51 AM
pandy   Not my forte, but shouldn't you split the belo...   Feb 7 2017, 11:05 AM
Jonah   The quote is for PHP to display the whole line. I...   Feb 7 2017, 11:29 AM
Christian J   The quote is for PHP to display the whole line. I...   Feb 7 2017, 11:41 AM
Christian J   Here is the code in the target window (echos pass...   Feb 7 2017, 11:10 AM
Jonah   I tried quoting the js function 'myPopup(...   Feb 7 2017, 11:26 AM
Christian J   Echoing the $uuid variable in a cell will sh...   Feb 7 2017, 11:37 AM
Jonah   If I enter a static value as a function argument, ...   Feb 7 2017, 11:53 AM
Christian J   If I pass the PHP variable as the argument to the...   Feb 7 2017, 03:17 PM
Jonah   The alert box will open and display the passed dat...   Feb 7 2017, 03:49 PM
Christian J   The alert box will open and display the passed da...   Feb 7 2017, 04:15 PM
Christian J   The JS function call parameter (created by the PHP...   Feb 8 2017, 01:26 PM
CharlesEF   The JS function call parameter (created by the PH...   Feb 9 2017, 02:19 AM
Christian J   I don't think that is correct. Only text val...   Feb 9 2017, 08:21 AM
CharlesEF   Yes, text values do need to be quoted but not numb...   Feb 9 2017, 12:41 PM
Christian J   Yes, text values do need to be quoted but not num...   Feb 9 2017, 04:25 PM
CharlesEF   Also, because of this bad HTML button code: echo ...   Feb 9 2017, 04:34 PM
Christian J   The problem only shows up when the $uuid val...   Feb 9 2017, 05:10 PM
CharlesEF   Or if the $uuid value is a string, and it...   Feb 9 2017, 06:17 PM


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 29th March 2024 - 03:43 AM