Jump to content

Dynamic?


Hooch
 Share

Recommended Posts

Hey all.Is it possible to have a dynamic field (for lack of a better word) in the

<script type="text/javascript"> dynamic stuff here </script>

tags?Code:

<script type="text/javascript" src="simplegallery.js">/************************************************ Simple Controls Gallery- (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><script type="text/javascript">var mygallery=new simpleGallery({	wrapperid: "simplegallery1", //ID of main gallery container,	dimensions: [250, 180], //width/height of gallery in pixels. Should reflect dimensions of the images exactly	imagearray: [		["http://i26.tinypic.com/11l7ls0.jpg", "http://en.wikipedia.org/wiki/Swimming_pool", "_new", "There's nothing like a nice swim in the Summer."],		["http://i29.tinypic.com/xp3hns.jpg", "http://en.wikipedia.org/wiki/Cave", "", ""],		["http://i30.tinypic.com/531q3n.jpg", "", "", "Eat your fruits, it's good for you!"],		["http://i31.tinypic.com/119w28m.jpg", "", "", ""]	],	autoplay: [true, 2500, 2], //[auto_play_boolean, delay_btw_slide_millisec, cycles_before_stopping_int]	persist: false, //remember last viewed slide and recall within same session?	fadeduration: 500, //transition duration (milliseconds)	oninit:function(){ //event that fires when gallery has initialized/ ready to run		//Keyword "this": references current gallery instance (ie: try this.navigate("play/pause"))	},	onslide:function(curslide, i){ //event that fires after each slide is shown		//Keyword "this": references current gallery instance		//curslide: returns DOM reference to current slide's DIV (ie: try alert(curslide.innerHTML)		//i: integer reflecting current image within collection being shown (0=1st image, 1=2nd etc)	}})</script>

This is the part I would like to draw from a DB

	imagearray: [		["http://i26.tinypic.com/11l7ls0.jpg", "http://en.wikipedia.org/wiki/Swimming_pool", "_new", "There's nothing like a nice swim in the Summer."],		["http://i29.tinypic.com/xp3hns.jpg", "http://en.wikipedia.org/wiki/Cave", "", ""],		["http://i30.tinypic.com/531q3n.jpg", "", "", "Eat your fruits, it's good for you!"],		["http://i31.tinypic.com/119w28m.jpg", "", "", ""]	],

Thank you for your time.

Link to comment
Share on other sites

You could use something like PHP to grab values from your DB and embed them in your script at download time.If you want to update them later, that's AJAX. You call a script on your server, which grabs your data. Then the script puts the data into a convenient format, like JSON, and sends it back. When the JSON string arrives at the javascript, you run it through eval(), and now you can (1) have brand new JavaScript objects, or (2) updated objects that already exist.For example, if AJAX.responseText comes back as '["http://some.jpg", "http://someplace/", "_new", "Hello!"]'Now you can do this:obj.imagearray[0] = eval(AJAX.responseText);So you're either assigning new data or replacing old. It doesn't matter. The point is that eval() lets you take data transmitted in string format and turn it into objects. And there's no limit to the number or kind. JSON is convenient. Your simpleGallery() basically returns objects in JSON format, so you already know it. XML works too, but you seem to be working with normal JavaScript objects, so I stuck with that.(NOTE. I'm doing this out of memory. Could be I missed a little something. But it's close.)

Edited by Deirdre's Dad
Link to comment
Share on other sites

Thanks Deirdre's Dad.The explanation you have given is way over my head. I wish it was drawn from xml...that I could figure out.

You could use something like PHP to grab values from your DB and embed them in your script at download time.
I'm not sure how I would add results to the <script></script> though. Can you elaborate?
Link to comment
Share on other sites

Easier than you think. This is just ONE way. If you're looping through a lot of DB rows, for example, it's easier just to build echo statements into the loop.

<?php	 $caption = "Birds in Spain";	 $year = 2001; ?> <!-- could be a bunch of HTML here --> <script type="text/javascript">	 var my_caption = "<?php echo $caption; ?>";	 var my_year = "<?php echo $year; ?>";  </script>

Edited by Deirdre's Dad
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...