Page 1 of 1

passing variable to javascript/php/mysql

Posted: Fri Dec 30, 2011 5:36 pm
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>";
?>

Re: passing variable to javascript/php/mysql

Posted: Tue Jan 03, 2012 2:09 am
by phpHappy
It seems it should open for $result['ExpenseID'] but knowing what that is isn't in your snippet.

Re: passing variable to javascript/php/mysql

Posted: Tue Jan 03, 2012 10:52 am
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>';
?>