Jump to content

Variables


Hooch
 Share

Recommended Posts

Hey all.Is it possible to put a variable into javascript?Heres a code I am using.

	<script type="text/javascript">var a = new Image(); a.src = 'zen_logo.png';var b = new Image(); b.src = 'zen_logo_over.png';var c = new Image(); c.src = 'zen_logo.png';var d = new Image(); d.src = 'images/calendar/calendar_jan.jpg';var e = new Image(); e.src = 'images/calendar/calendar_feb.jpg';var f = new Image(); f.src = 'images/calendar/calendar_mar.jpg';var g = new Image(); g.src = 'images/calendar/calendar_apr.jpg';var h = new Image(); h.src = 'images/calendar/calendar_may.jpg';var i = new Image(); i.src = 'images/calendar/calendar_jun.jpg';var j = new Image(); j.src = 'images/calendar/calendar_jul.jpg';var k = new Image(); k.src = 'images/calendar/calendar_aug.jpg';var l = new Image(); l.src = 'images/calendar/calendar_sep.jpg';var m = new Image(); m.src = 'images/calendar/calendar_oct.jpg';var n = new Image(); n.src = 'images/calendar/calendar_nov.jpg';var o = new Image(); o.src = 'images/calendar/calendar_dec.jpg';</script>

Now I want to link this page, but there are multiple calendars now.So the images might be:images/calendar_dogs/calendar_dec.jpg orimages/calendar_cats/calendar_dec.jpg etc.Via PHP I will have the variable set as follows...$_GET['calendar']And $_GET['calendar'] could be dogs, cats, cars or anything for that matter.Thank you for your time

Link to comment
Share on other sites

Hey all.Is it possible to put a variable into javascript?Heres a code I am using.
	<script type="text/javascript">var a = new Image(); a.src = 'zen_logo.png';var b = new Image(); b.src = 'zen_logo_over.png';var c = new Image(); c.src = 'zen_logo.png';var d = new Image(); d.src = 'images/calendar/calendar_jan.jpg';var e = new Image(); e.src = 'images/calendar/calendar_feb.jpg';var f = new Image(); f.src = 'images/calendar/calendar_mar.jpg';var g = new Image(); g.src = 'images/calendar/calendar_apr.jpg';var h = new Image(); h.src = 'images/calendar/calendar_may.jpg';var i = new Image(); i.src = 'images/calendar/calendar_jun.jpg';var j = new Image(); j.src = 'images/calendar/calendar_jul.jpg';var k = new Image(); k.src = 'images/calendar/calendar_aug.jpg';var l = new Image(); l.src = 'images/calendar/calendar_sep.jpg';var m = new Image(); m.src = 'images/calendar/calendar_oct.jpg';var n = new Image(); n.src = 'images/calendar/calendar_nov.jpg';var o = new Image(); o.src = 'images/calendar/calendar_dec.jpg';</script>

Now I want to link this page, but there are multiple calendars now.So the images might be:images/calendar_dogs/calendar_dec.jpg orimages/calendar_cats/calendar_dec.jpg etc.Via PHP I will have the variable set as follows...$_GET['calendar']And $_GET['calendar'] could be dogs, cats, cars or anything for that matter.Thank you for your time

If your page is using PHP, you can just write the value of the variable onto the page:
var d = new Image(); d.src = 'images/calendar/calendar_<?php echo $_GET['calendar']; ?>.jpg';

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