passing variable to javascript/php/mysql

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

passing variable to javascript/php/mysql

Post by cjkeane »

Everyone:

I need to pass a variable to javascript so that i can popup a window. it must be a defined sized popup window and display the appropriate data from mysql. My code does popup a window, however it doesn't link the proper id to the page which opens. it seems to open a popup with the same ExpenseID no matter which record is clicked on. I'd appreciate any helpfui ideas you may have.

this is just an excerpt from my code to simplify troubleshooting.

Code: Select all

<?php
	echo "<tbody>";
	echo "<tr class='bb' onMouseOver=\"this.bgColor = '#dbebf7'\" onMouseOut =\"this.bgColor = '#FFFFFF'\">";	
	?>
        <script language="JavaScript" type="text/javascript">
			function confirmExpenseRecord() 
			{window.open("er_expenserecordsavedb.php?ExpenseID=<?php echo $result['ExpenseID']  ?>","_blank","toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, resizable=yes, width=800, height=550");}
		</script>
	<?php
	echo '<td nowrap valign="top"><a href="er_expenserecordsavedb.php?ExpenseID=' . $result['ExpenseID'] .'" onclick="confirmExpenseRecord(); return false;">'. $result['ActionItem'].' </a></td>';
    echo '<td nowrap valign="top"><a href="er_expenserecordsavedb.php?ExpenseID=' . $result['ExpenseID'] .'" onclick="confirmExpenseRecord(); return false;">'. $result['CompanyName'].' </a></td>';
	echo '<td nowrap valign="top">' . $result['DateFirstDay'] . '</td>';
	echo '<td nowrap valign="top">' . "$". number_format($result['MegaInvoiceAmount'],2) .  '</td>';
	echo '<td nowrap valign="top">' . $result['DateService'] . '</td>';
	echo '<td nowrap valign="top">' . nl2br($result['ActionTextField']) . '</td>';
	echo '<td nowrap valign="top">' . $result['PaidBy'] . '</td>';
  echo "</tr>"; 
  echo "<tbody>";
?>
phpHappy
Forum Commoner
Posts: 33
Joined: Wed Oct 26, 2011 1:58 pm

Re: passing variable to javascript/php/mysql

Post by phpHappy »

It seems it should open for $result['ExpenseID'] but knowing what that is isn't in your snippet.
cjkeane
Forum Contributor
Posts: 217
Joined: Fri Jun 11, 2010 1:17 pm

Re: passing variable to javascript/php/mysql

Post by cjkeane »

Thanks for the reply. I've somewhat figured it out, however not quite the way i'd like it to function.

$result['ExpenseID'] is defined/retreived by:
$query = mysql_query($string) or die (mysql_error());
$result = mysql_fetch_array($query);

I'm now using the below code which does popup a window:

Code: Select all

<?php
echo '<td nowrap><a href="er_expenserecordsavedb.php?ExpenseID=' . $result['ExpenseID'] .'"  onclick="window.open(this.href, width=800, height=550); return false"> '. $result['ActionItem'] . '</a></td>';
?>
however if i re-write the code to include all of the window options, the below code opens the window in the same window, not a popup window. Do you have any ideas why?

Code: Select all

<?php
echo '<td nowrap><a href="er_expenserecordsavedb.php?ExpenseID=' . $result['ExpenseID'] .'"  onclick="window.open(this.href, toolbar=no, location=yes, status=no, menubar=no, scrollbars=yes, resizable=yes, width=50, height=50); return false"> '. $result['ActionItem'] . '</a></td>';
?>
Post Reply