Milonic provide full featured pull down web menus for some of the worlds largest companies
click here to see what it can do for you

Download Milonic DHTML Menu
Buy Milonic DHTML Menu

Back To Start Of Archive
Taken From The Forum: Help & Support for DHTML Menu Version 5+
Forum Topic: Click to view post
Last Updated: Saturday July 14 2012 - 06:07:15

Using variable in URL=


Poster: mjstehn
Dated: Wednesday August 11 2004 - 15:04:53 BST

I searched and did not find anything related to this. I would like to use a variable in the url= section of the menu. I am going to set a variable equal to the current date and I want a current weeks news to open that file according to the date. Is is possible to use a variable in the url=, if so are there any special quotes or anything that need to be used? Thanks,


Poster: John
Dated: Wednesday August 11 2004 - 17:25:16 BST

Yes, it is possible.

What language?


Poster: mjstehn
Dated: Wednesday August 11 2004 - 19:15:42 BST

Javascript. I just want to add some Javascript code to the existing menu file. I will get the current month and day and create a string with .pdf at the end. I just want to use that variable for my url.

Thanks,


Poster: kevin3442
Dated: Wednesday August 11 2004 - 23:12:28 BST

The aI() function is used to create a menu item. The paramted passed to that funtion when you define an item is a string (like "text=item text;url=http://www.whatever.com;"). In most examples you see the parameter passed to aI() is a literal string (text inside of quotes). But you can also do string concatenation to produce the single parameter from any combination of literals, string variables, and functions that return strings.

So, at the top of your menu_data.js file, you could make a function that builds a four digit string representing the month and day (mmdd), incorporate that into a url, then return the entire url. Like so.
Code:
function getNewsURL()
{
  var currentDate = new Date();
  var currentMonth = currentDate.getMonth() + 1
  if (currentMonth < 10) currentMonth = "0" + currentMonth;
  var currentDay = currentDate.getDate();
  if (currentDay < 10) currentDay = "0" + currentDay;
  var newsURL = "http://www.newstuff.com/news/" + currentMonth + currentDay + ".pdf";
  return newsURL;
}


You could then incorporate the returned url into the aI() parameter by calling that function part way through building the string for the aI() parameter, like so:
Code:
aI("text=News of the Day;url=" + getNewsURL() + ";status=Read the news;");


For today, the menu item above would have a url pointing to:
Code:
http://www.newstuff.com/news/0811.pdf


Hope that helps,

Kevin


Poster: mjstehn
Dated: Thursday August 12 2004 - 4:17:05 BST

Exactly what I was trying to do. Works great. I appreciate your help. I had the function OK, I just did not know to use the " + function + " in the url section.

Thanks again,

Mike