Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Creating Dynamically generated Javascript

    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.
    Code:
    <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:

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

    Viewing the source from my browser shows this:
    Code:
    <a href="javascript:void showWindow("contactinfo.php?cid=104"); ">John Doe</a>

    My JScript looks like this:
    Code:
    <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
    Last edited by dmilani; 09-29-2008 at 02:51 AM.

  • #2
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    2
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  • Users who have thanked hola001 for this post:

    dmilani (09-29-2008)

  • #3
    New Coder
    Join Date
    Nov 2006
    Location
    Malvern, PA
    Posts
    33
    Thanks
    2
    Thanked 0 Times in 0 Posts
    That was it. Thanks Hola!

    For the record the PHP needs to look like this:

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

    And the Javascript looks like this:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •