...

View Full Version : Resolved Creating Dynamically generated Javascript



dmilani
09-28-2008, 12:47 AM
Hello,

This is my first attempt at AJAX. I have a solid understanding of PHP. I have a PHP page that lists some data from a query. I am trying to use a pop-up window to show more detailed data. I started out by hardcoding the script with the url and it worked. When I tried to generate it dynamically it breaks. I am working off of the Prototype and Prototype-Window frameworks.

The original javascript code looks like this.


<html>
<head>
<script type="text/javascript" src="javascripts/prototype.js"></script>
<script type="text/javascript" src="javascripts/effects.js"></script>
<script type="text/javascript" src="javascripts/window.js"></script>
<script type="text/javascript" src="javascripts/window_effects.js"></script>

<link href="themes/default.css" rel="stylesheet" type="text/css" ></link>
<link href="themes/spread.css" rel="stylesheet" type="text/css" ></link>
</head>

<body>

<a href="javascript:void showWindow();">Show Window</a>

<script>
function showWindow()
{
win = new Window( { className: 'spread', url: 'test.html',
title: 'Simple Window', width:400,
height:300, destroyOnClose: true, recenterAuto:false } );
win.showCenter();
}
</script>
</body>
</html>



My attempt at making it dynamic:



echo "<a href=\"javascript:void showWindow(\"contactinfo.php?cid=" .$row['contactID']. "\"); \">" .$row['fname']. " " .$row['lname']. "</a>" ;




Viewing the source from my browser shows this:


<a href="javascript:void showWindow("contactinfo.php?cid=104"); ">John Doe</a>



My JScript looks like this:


<script>
function showWindow(link) {
win = new Window( {
className: 'alphacube', url: '(link)' , title: '', width:350, height:200, destroyOnClose: true, recenterAuto:false
} );
win.showCenter();
}
</script>


One curious thing is that when I mouse over the link the status bar displays:
Run Script: "void%20showWindow("

I suspect my modifications to the script are wrong but haven't been able to find an example of how to do this.

Thanks for looking and thanks for any suggestions.

Dan

hola001
09-28-2008, 07:12 AM
By looking at the source from the browser I would say the html is rendering everthing between the first and second quotes. Try using single quotes.

dmilani
09-29-2008, 03:49 AM
That was it. Thanks Hola!

For the record the PHP needs to look like this:



echo "<a href=\"javascript:void showWindow('contactinfo.php?cid=" .$row['contactID']. "'); \">" .$row['fname']. " " .$row['lname']. "</a>" ;



And the Javascript looks like this:



<script>
function showWindow(link) {
win = new Window( {
className: 'alphacube', url: (link) , title: '', width:350, height:200, destroyOnClose: true, recenterAuto:false
} );
win.showCenter();
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum