Dynamic Hyperlink


 
Thread Tools Search this Thread
Top Forums Web Development Dynamic Hyperlink
# 1  
Old 01-03-2012
Dynamic Hyperlink

Hi Guys/ Gals,

I am trying to create a link based on the current date however it doesnt seem to work.

Could someone please point me in the right direction.

Here is what i have so far..

HTML Code:
<html>
  <head>
    <script type="text/javascript" language="JavaScript">
      function getDate()
      {
        var now = new Date();
        var month	= now.getMonth();
        var day = now.getDate();
        var year = now.getYear();
        if(year < 2000) { year = year + 1900; }
        var dateString = 'http://test.com/' + monthnumber + '-' + monthday + '-' + year + '.html';
        return dateString;
      } // function getCalendarDate()		
    </script>
  </head>
	
  <body>
     <a href="javascript:getDate()">Today</a>
  </body>
</html>
thanks in advance,

Rob.
# 2  
Old 01-03-2012
You have to explicitly set the link rather than expecting it to be evaluated on the fly. There are JS libraries that implement sprintf also consider the ternary operator in this context eg month>10 ? month +1 : '0' + (month +1) for more legible filenames
Code:
<html>
  <head>
    <script type="text/javascript" language="JavaScript">
      function setLink(variableLink)
      {
        var now = new Date();
        var month    = now.getMonth();
        var day = now.getDate();
        var year = now.getYear();
        if(year < 2000) { year = year + 1900; }
        //var dateString = sprintf("http://test.com/%2d-%2d-%4d.html" ,
        //                         month, day,year);
        var dateString ='http://test.com/'
                                  + month + '-'
                                  + day   + '_'
                                  + year  + '.html';
        var anchor=document.getElementById(variableLink);
        anchor.href=dateString;
      }
    </script>
  </head>
    
  <body "onLoad=setLink('variableLink');">
     <a Id="variableLink" href="">Today</a>
  </body>
</html>

This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 01-03-2012
Works like a charm, thanks alot Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Sql dynamic table / dynamic inserts

I have a file that reads File (X.txt) Contents of record 1: rdrDESTINATION_ADDRESS (String) "91 971502573813" rdrDESTINATION_IMSI (String) "000000000000000" rdrORIGINATING_ADDRESS (String) "d0 movies" rdrORIGINATING_IMSI (String) "000000000000000" rdrTRAFFIC_EVENT_TIME... (0 Replies)
Discussion started by: magedfawzy
0 Replies

2. AIX

Connect to AIX via Windows hyperlink

We do not have a console for our box so we are trying to hyperlink in - does anyone know the settings? (9 Replies)
Discussion started by: vbagwell
9 Replies

3. AIX

HELP!windows hyperlink to 9600 baud 8N1

We are trying to use the Windows hyperlink as a console to our AIX box. We are using 9600 baud 8N1. (1 Reply)
Discussion started by: vbagwell
1 Replies

4. AIX

hyperlink settings

Does anyone know the hyperlink settings to look at an AIX5L box? (1 Reply)
Discussion started by: vbagwell
1 Replies

5. Shell Programming and Scripting

Using Perl to add hyperlink to html files

Hi , I have written a csh script which will output file named " myoutput.html " displayed below. I am tried to ftp this html file into a local web server so that it can be displayed to public sharing this server and i would want to add a hyperlink to " XX " , " YY " , " ZZ ". Can this be done... (17 Replies)
Discussion started by: Raynon
17 Replies

6. UNIX for Dummies Questions & Answers

Create Hyperlink

Hi Everybody, I am new to this forum. I need help. Here is the details: I have a .csv file in unix server which is 2MB size I am attaching this file and sending to all users who are in my team thru Microsoft outlook. All users requested me to send the link where we can click and open... (1 Reply)
Discussion started by: utham1
1 Replies

7. Shell Programming and Scripting

Awk scripting and usage of regex to locate a hyperlink

Hello guys, I need to write awk script that would take an html page and output a list of each unique http link on that webpage followed by the number of times it occurred in that file. e.g. ----------------------------------------- Webpage: index.html http://www.google.com/ 3... (1 Reply)
Discussion started by: grinch
1 Replies

8. Shell Programming and Scripting

How to add Hyperlink with shell script(using mail client)

Hi ! plz let me suggest ..... By using of mail client methods I am trying to send mails through shell script. like.... To: From: Sub: Body: some sample text..... <my requirement is how to add hyper link to some text(click me) ... (0 Replies)
Discussion started by: rsukumar
0 Replies

9. UNIX for Dummies Questions & Answers

Moving .html files while preserving hyperlink integrity?

Hi, I use a Windows-based program called <a href="http://www.coast.com">Coast Webmaster</a> for moving large numbers of HTML files in one directory to another directory. As you drag and drop each file or entire directory of files to new locations in the web root directory tree, this utility... (1 Reply)
Discussion started by: Buddy123
1 Replies
Login or Register to Ask a Question