KenHorse Posted March 6, 2013 Share Posted March 6, 2013 I have a php generated webpage that reads in data from a MySQL database and displays it. One of the database fields being displayed can be moused over and it creates a link. (this is adapted code so I can't say it ever worked).In the beginning of the code is this: <SCRIPT LANGUAGE=JavaScript>function smallpopUp(url) {myWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=1,height=1');self.name = "mainWin"; }</SCRIPT>Later in the code, is this (this generates the link based on the mouse-over)print "</td> <td> <a href=\"javascript:smallpopUp('sendcmd.php?cmd=$prefix$row[code]')\"> $row[code]</a> </td> </tr>";What is supposed to happen is that when any displayed entry is clicked, the script sendcmd.php is supposed to be called (this part works) and the value of $cmd passed to it. Of course $cmd is empty at the popup window (sendcmd.php).What do I need to do in order to make this work?[/code] Link to comment https://forums.phpfreaks.com/topic/275319-passing-variable-from-javascript-to-new-php-script/ Share on other sites More sharing options...
Psycho Posted March 6, 2013 Share Posted March 6, 2013 Well, it could be a number of things. Have you checked the HTML source code to see if there is actually any value following: sendcmd.php?cmd= If no, then the variables $prefix and $row[code] are likely not set. Or, are you trying to use those to reference a variable variable? If yes, then the script sendcmd.php is likely not referencing that value correctly. Based upon your description, I think the problem is the former - the variables are not set when the page is created. Where are $prefix and $row[code] defined? Link to comment https://forums.phpfreaks.com/topic/275319-passing-variable-from-javascript-to-new-php-script/#findComment-1416954 Share on other sites More sharing options...
KenHorse Posted March 7, 2013 Author Share Posted March 7, 2013 Well, it could be a number of things. Have you checked the HTML source code to see if there is actually any value following: sendcmd.php?cmd= If no, then the variables $prefix and $row[code] are likely not set. Or, are you trying to use those to reference a variable variable? If yes, then the script sendcmd.php is likely not referencing that value correctly. Based upon your description, I think the problem is the former - the variables are not set when the page is created. Where are $prefix and $row[code] defined? Yes there is and it shows in the URL. $Prefix and $row are the results of reading in MySQL data. I know they exist because they're displayed on the generated page just fine. Here's the complete page source <HTML> <title>Arcom RC210 Web RCP</title> <HEAD> <link rel="Stylesheet" rev="Stylesheet" href="stylesheet.css" type="text/css" media="Screen"> </HEAD> <body leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0"> <table class="transp" width="100%" height="100%" cellspacing="0" cellpadding="2"> <tr><td height="1%" bgcolor="#D4C69A" class="nav" nowrap> <a href="index.php">Home</a> <a href="macros.php">Macros</a> <a href="setpoints.php">Set Points</a> <a href="ports.php?port=1&tab=1">Port & Global Programming</a> <a href="codes.php">Command Codes</a> <a href="dvr.php">DVR</a> <a href="control.php">CONTROL</a> <a href="vocab.php">Word List</a> <a href="mfunctions.php">Macro Functions</a> <a href="irlp.php">IRLP</a> <a href="rc2105_5manual.pdf" target="_blank">RC210 5.50 Manual</a> </td></tr> <TR><TD height="98%" valign=\"top\"> <SCRIPT LANGUAGE=JavaScript> function smallpopUp(url) { myWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=0,width=1,height=1'); self.name = "mainWin"; } </SCRIPT> <!-- <script language="JavaScript"> var Result = ""; location.href="sendcmd.php?cmd=" + Result; </script> --> <BR> <H2 align="center" class="primarycolor">Command Codes</H2> <P align="center">Click the function number on the left to send the command code.<BR> <!-- Click the link on the right to send the command.</P> --> <table align="center" border=0 cellspacing=0 cellpadding=0 width="600"> <tr > <td colspan=4 height="50" valign="bottom"><TABLE BORDER="0" CELLPADDING=0 CELLSPACING=0 WIDTH="400" align="LEFT"><TR> <td rowspan="2"> </td> <TD BGCOLOR="D4C69A" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="D4C69A" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablinkselected" HREF="codes.php?tab=alarms">Alarms</A><BR> </TD> <TD BGCOLOR="D4C69A" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=linking">Linking</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=auxaudio">Aux Audio</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=ufoutputs">Digital outputs</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=Port1">Port 1</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=Port2">Port 2</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=Port3">Port 3</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=Remote Base">Remote Base</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> <TD BGCOLOR="500000" ALIGN=LEFT VALIGN=TOP> <IMG height="9" src="tab-left.gif" width="9"><BR> </TD> <TD BGCOLOR="500000" width="11%" ROWSPAN=2 ALIGN="MIDDLE"> <A class="tablink" HREF="codes.php?tab=misc">Misc</A><BR> </TD> <TD BGCOLOR="500000" ALIGN="RIGHT" VALIGN="TOP"> <IMG height="9" src="tab-right.gif" width="9"><BR> </TD> <td rowspan="2"> </td> </tr><tr> <TD BGCOLOR="D4C69A"> </TD> <TD BGCOLOR="D4C69A"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> <TD BGCOLOR="500000"> </TD> </tr></table> </td> </tr><tr> <td class="lightrow"> <table align="center" border=0 cellspacing=0 cellpadding=4 width="100%"> <TR class="darkrow"> <td> </td> <td>Alarm 1 OFF </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#1910')"> 1910</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 1 ON </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#1911')"> 1911</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 1 Interogate </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#1913')"> 1913</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 2 OFF </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#2910')"> 2910</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 2 ON </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#2911')"> 2911</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 2 Interogate </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#2913')"> 2913</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 3 OFF </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#3910')"> 3910</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 3 ON </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#3911')"> 3911</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 3 Interogate </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#3913')"> 3913</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 4 OFF </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#4910')"> 4910</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 4 ON </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#4911')"> 4911</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 4 Interogate </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#4913')"> 4913</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 5 OFF </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#5910')"> 5910</a> </td> </tr> <TR class="lightrow"> <td> </td> <td>Alarm 5 ON </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#5911')"> 5911</a> </td> </tr> <TR class="darkrow"> <td> </td> <td>Alarm 5 Interogate </td> <td> <a href="javascript:smallpopUp('sendcmd.php?cmd=#5913')"> 5913</a> </td> </tr></table></td></tr></table><tr><td height="1%"> <table width="100%" class="darkrow" cellpadding="3" cellspacing="0"><tr><td> Copyright© 2005 - 2013 by Arcom Communications. All Rights Reserved. </td></tr></table> </td></tr></table> </body> </html> Link to comment https://forums.phpfreaks.com/topic/275319-passing-variable-from-javascript-to-new-php-script/#findComment-1417332 Share on other sites More sharing options...
Hall of Famer Posted March 8, 2013 Share Posted March 8, 2013 Actually I am kinda curious at how you pass variables around from PHP and Javascript, since I've never been able to do this. Link to comment https://forums.phpfreaks.com/topic/275319-passing-variable-from-javascript-to-new-php-script/#findComment-1417387 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.