1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

passing values between JS and PHP Heeeelp me!!!!

Discussion in 'PHP' started by oliveawn, Dec 11, 2005.

  1. #1
    Howdy!!!!!

    I'm kinda new is this game and have problems passing a variable from a parent window to a child window. I have a table filled with some info from a database. One of the columns contains a description which needs more space than the table column to display. My choice here was to display this description in a new popup-window using javascript window.open. I want to pass the ID value(from the database) and pass it to the new URL(new description) popup window. I of course need this ID value to be able to pick the correct description of the row chosen. This is how I get the value and call my javascript function from the table:
    print "<tr><td>".$row[1]."</td><td>".$row[2]."</td><td>".$row[3]."</td><td>".$row[4]."</td><td>".$row[5]."</td><td>".$row[6]."</td><td>".$row[7]."</td><td align='center'><a href='javascript:Description(".$row[0].");'>?</a></td></tr>";

    where $row[0] of course is the ID of that row. I've tried in more than various ways to modify the js funciton Description to make it pass the value to another window. If someone knows the answer to this riddle and how to recieve the value in the other window(URL) I would be more than grateful.
    I really look forward to see some answers
     
    oliveawn, Dec 11, 2005 IP
  2. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #2
    Probaly get this wrong as js + php are pain... Any how rewrite the a href bit like this
    a href=\"javascriptescription('{$row[0]}') \"> 
    PHP:
    Just in case i fluffed that remember ' "" ' is not value you need to escape the quotes to get a sinlge set between double.Also reference to an array should be enclosed between {} when used in a string
     
    Big 'G', Dec 11, 2005 IP
    madkad likes this.
  3. oliveawn

    oliveawn Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    thanks for you time, but this is not the problem( maybe I didn't explain the problem very good). The value is sent to the js function Description() with the value of row[0]. This is where I would like to pass the value to the URL named info.php. I'm not sure if this is the right approach to do this at all. I've tried to use
     $IdOfRow =$_GET['n'];
    PHP:
    to obtain the value in the info.php file without any luck. As I said this may not at all be the correct approach so if anyone have a better idea please enlighten me with your wisdom.

    function Description(ID)   {   
    	win = window.open('info.php?n = +ID ','description',' scrollbar = yes,status = no,directories=no,location = 0,width = 300, height = 350');}
    Code (markup):
     
    oliveawn, Dec 12, 2005 IP
  4. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #4
    Okay slight crossed wires i think. New to helping :)

    Okay you can pass the varible to JS no problem.. Just to double check this is happening it may help to add an alert for the var to ensure it is passing what you want
    
    function Description(ID)   { 
    	<!--Just to check the right Var is being passed--//>
    	alert(ID)  
    	<!-- The ID needs to be processed seperate not in the string 'n=' +ID , NOT 'n=+ID'
    	win = window.open('info.php?n =' +ID ,'description',' scrollbar = yes,status = no,directories=no,location = 0,width = 300, height = 350');
    }
    
    Code (markup):
    Hope this helps Obviously info.php can then access the var ID by a number of ways such as
    $x =$_GET['n'];

    Still unsure whether you want to pass the whole descrition or you just want to pass the rowid for the descrition. The latter would result in you create a new sql statement to get the contents
     
    Big 'G', Dec 12, 2005 IP
  5. oliveawn

    oliveawn Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank's for your time big'G'!!!!!!

    I've already checked the value in the js function with alert() and everyting is alright that far(the value is there). I didn't really understand your next tip though but I desperately tried anyway without any luck. What I want to do is pass the value to the info.php URL in order to use it in a mysql statement as you expected. The ID from row[0] is the ID from a row in the database. When I clicl the questionmark I wanna get the description from the same row in the new window(containing info.php).However maybe I misunderstood you but the I still can't pass the value. Really look forward to another reply.
     
    oliveawn, Dec 12, 2005 IP
  6. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #6
    If the value is available and correct using alert. Their their is no reason why it should not pass. the only problem i can see is a slight typo above,their was a space between the n and the = (n =) this means that any reference to "n" would be invalid as in the url it would be set as "n " Any how fire it up with the script below. Note the +ID is not enclosed between ' '
    The correct script is below

    
    function Description(ID)   { 
    	win = window.open('info.php?n='+ID ,'description',' scrollbar = yes,status = no,directories=no,location = 0,width = 300, height = 350');
    }
    
    Code (markup):
    then the php code for info.php
    
    <?php
    
    echo "The var being passed is ". $_GET['n'];
    ?>
    
    PHP:
     
    Big 'G', Dec 13, 2005 IP
  7. Big 'G'

    Big 'G' Member

    Messages:
    89
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    48
    #7
    If the value is available and correct using alert. Their their is no reason why it should not pass. the only problem i can see is a slight typo above,their was a space between the n and the = (n =) this means that any reference to "n" would be invalid as in the url it would be set as "n " Any how fire it up with the script below. Note the +ID is not enclosed between ' '
    The correct script is below

    
    function Description(ID)   { 
    	win = window.open('info.php?n='+ID ,'description',' scrollbar = yes,status = no,directories=no,location = 0,width = 300, height = 350');
    }
    
    Code (markup):
    then the php code for info.php
    
    <?php
    
    echo "The var being passed is ". $_GET['n'];
    ?>
    
    PHP:
     
    Big 'G', Dec 13, 2005 IP
  8. oliveawn

    oliveawn Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Jiiiiiiiiiiiiihouuuu!!!!!, finally everything works as expected. That little problem almost had me ripping my hair of my head. Thank you very much for your help big'G'.
     
    oliveawn, Dec 13, 2005 IP