#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    81
    Rep Power
    16

    I need help with passing a variable from a php file to a .js


    hi

    I have a problem that i cant figure out and have been on it all day.

    I have a file that is php and has this inside it.

    Code:
    <script type="text/javascript" src="/media/getalbumpics.php?id=<?php echo $myrow['ID'];?>&folder=<?php echo $myrow['ID'];?>"></script>
    <script type="text/javascript"> var myvar = "<?php echo $myrow['ID'];?>"; </script> 
    <script type="text/javascript" src="/media/ddphpalbum.js">
    /***********************************************'.
    * PHP Photo Album script v2.0- (c) Dynamic Drive DHTML code library (www.dynamicdrive.com)
    * This notice MUST stay intact for legal use
    * Visit Dynamic Drive at http://www.dynamicdrive.com/ for this script and 100s more
    ***********************************************/'.
    </script>
    <link rel="stylesheet" type="text/css" href="/media/ddphpalbum.css" />	 
    <?php
    		 
    		 echo
    		 "<div class='entry-trow3'><script type='text/javascript'>".
             "new {$myrow['ID']}({".
    	     "albumvar: {$myrow['ID']},".
    	     "dimensions: [6,2],".
    	     "sortby: ['file', 'asc'],".
    	     "showsourceorder: false,".
    	     "onphotoclick:function(thumbref, thumbindex, thumbfilename){".
    		 "thumbnailviewer.loadimage(thumbref.src, \"fit2screen\")".
    	     "} }) </script>";

    then in ddphpalbum.js which is referenced above i have
    Code:
    function myvar(setting){
    	this.albumvar=setting.albumvar
    	this.albumvar.images.pop() //remove last "dummy" array element
    	for (var i=0; i<this.albumvar.images.length; i++){
    		if (this.albumvar.desc[i]) //if a manual desc exists for this image
    			this.albumvar.images[i][3]=this.albumvar.desc[i] //extend image array with desc
    	}

    what im trying to do is, make myvar be a variable through out the whole .js file

    I want this variable to come from the php page though, so far no success doing it this way. How do i send and show the variable in the .js file?

    i need function myvar(setting) to be something like function $myvar(setting)
  2. #2
  3. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2009
    Location
    London, ON
    Posts
    322
    Rep Power
    219
    Please look at the main "Java Help" forum. Look at the stickies. See that one labeled [NEW USERS] - This is not the Javascript forum!?

    Mmhmm. Welcome, anyway. I don't suggest you re-post. A moderator will likely move this to the JS forum.
    <Tetrad> the program I just wrote 1) compiled the first time without any errors and 2) worked like it was supposed to
    <Tetrad> I don't know whether to be proud or scared to death
    Originally Posted by DaWei_M
    That covers a multitude of your sins, right there.
  4. #3
  5. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    Originally Posted by Wetmelon
    Mmhmm. Welcome, anyway. I don't suggest you re-post. A moderator will likely move this to the JS forum.
    There's a "report bad post" at the top-right of each post that you can use to alert the mods that a thread is in the wrong forum. Makes the move quicker the earlier it's reported (you won't see it for this one, as I've reported it now, but you'll see it in future posts).

    Comments on this post

    • Wetmelon agrees : Oh. Thank you, and will do in the future :)
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    81
    Rep Power
    16
    Originally Posted by ishnid
    There's a "report bad post" at the top-right of each post that you can use to alert the mods that a thread is in the wrong forum. Makes the move quicker the earlier it's reported (you won't see it for this one, as I've reported it now, but you'll see it in future posts).
    well i tried waiting, but i need help so ill go repost.
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2003
    Posts
    81
    Rep Power
    16
    actually forget it, i hate this site.

    Comments on this post

    • jzd disagrees
    • tfecw agrees
  10. #6
  11. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2007
    Posts
    1,939
    Rep Power
    3122
    If you take the time to read the sticky posts BEFORE you post (like you should on any forum), then you would not end up posting it in the wrong forum where few people will pay attention to it.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Nov 2004
    Location
    Washington DC
    Posts
    2,755
    Rep Power
    1576
    jzd disagrees!
    tfecw agrees!
    I fail at disagreeing

    Comments on this post

    • Wetmelon agrees
    Open for extension, closed for modification
  14. #8
  15. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    Originally Posted by seanincali
    actually forget it, i hate this site.
    Because of this thread? I don't see anything else in your thread history that would cause this kind of reaction.

    You posted a question about JavaScript and PHP in the wrong forum. This is why you didn't get the responses you wanted, that's all.

IMN logo majestic logo threadwatch logo seochat tools logo