jonlake
asked on
Variables in Javascript URL
Hi, I'm new to Javascript so bear with me please.
I have a series of slides in Adobe Captivate. Each slide has a button on it. When the user clicks the button it should take them to a URL which is partially made up of today's date, e.g:
http://10.10.10.10/abcd/web/day.php?year=2012&month=11&day=01&area=12
I played with setting the variables and using window.open but cannot get it to work. As I said I'm new to Javascipt so any help would be appreciated, and merry Xmas!
Thanks
I have a series of slides in Adobe Captivate. Each slide has a button on it. When the user clicks the button it should take them to a URL which is partially made up of today's date, e.g:
http://10.10.10.10/abcd/web/day.php?year=2012&month=11&day=01&area=12
I played with setting the variables and using window.open but cannot get it to work. As I said I'm new to Javascipt so any help would be appreciated, and merry Xmas!
Thanks
ASKER
I may not have explained myself very well. I need to create the three variables, year, month and day based upon whichever day it happens to be. Something like this:
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
Those variables then need to populate into the URL. Once I have the URL created isn't it a smple onclick event?
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
Those variables then need to populate into the URL. Once I have the URL created isn't it a smple onclick event?
ASKER
I found this code which nicely opens a browser window. My though process is that there my be a way to pass the date variables into the URL:
var simmy = window.open("http://www.google.com", "simWindow","status=0,menu Bar=0,loca tion=0,too lBar=0,dir ectories=0 ,resizable =0,scrollb ars=0,heig ht=620,wid th=980");
var simmy = window.open("http://www.google.com", "simWindow","status=0,menu
You can develop a JavaScript function that will dynamically insert the variables and variable names into a URL. Example follows:
var url = "http://www.google.com?year="+year+"&month="+month+"& day="+day+ "&area="+a rea;
The final markup would look something like this:
Does this help you move in the right direction?
Just in case you want to use PHP to generate your variable data, you can use
var url = "http://www.google.com?year="+year+"&month="+month+"&
The final markup would look something like this:
<script type="text/javascript">
var month = "12";
var day = "12";
var year = "2012";
var area = "02";
var url = "http://www.google.com?year="+year+"&month="+month+"&day="+day+"&area="+area;
document.write("<a href="+url+">this link");
</script>
Does this help you move in the right direction?
Just in case you want to use PHP to generate your variable data, you can use
<?php
$sysdate = date("d,m,Y");
?>
This will return a variable value of DDMMYYYY format and it can be altered to include special characters in the return value.
ASKER
This has worked:
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
if(month<10){month='0'+mon th};
var day = currentTime.getDate("dd");
if(day<10){day='0'+day};
var year = currentTime.getFullYear();
var area = "02";
var simmy = window.open("http:"+"/"+"/"+"1 0.10.10.10 "+"/"+"mrb s"+"/"+"we b"+"/"+"da y.php"+"%3 F"+"year=" +year+"%26 "+"month=" +month+"%2 6" +"day="+day+"%26"+"area="+ area, "simWindow","status=0,menu Bar=0,loca tion=0,too lBar=0,dir ectories=0 ,resizable =0,scrollb ars=0,heig ht=620,wid th=980");
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
if(month<10){month='0'+mon
var day = currentTime.getDate("dd");
if(day<10){day='0'+day};
var year = currentTime.getFullYear();
var area = "02";
var simmy = window.open("http:"+"/"+"/"+"1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, you steered me in the right direction.
Based on the URL example you provided, you are using a _GET method to submit form data to the next page using PHP.
What you will need to do is embed a PHP script within your JavaScript to dynamically generate the values needed for the JavaScript to work. See example below:
Open in new window
At this point you can use the variables generated by PHP within your JavaScript construct using the JavaScript variables. Notice the difference between the PHP variable and JavaScript syntax. PHP uses the $ symbol to denote a variable, but JavaScript does not require any prefix.