Satch3000
Satch3000

Reputation: 49384

Javascript generated dynamic link from array

I need a bit of help here.

I have some code which collects dates and places them in a Calendar.

It works fine but I need 1 more thing, which is to add a link for each date.

Up to now I have hardcode a link and it works but I need to make each link to it's own page.

This is my hardcoded link:

$('<div><a href="view-paginated.php#&ui-page=Event-Date--3-10-2011-0">' + today + '</a></div>')

The array holds just the dates, so it would contain this: "3-10-2011" .. without the quotes.

Here is the code which gets the dates and populates the Calendar:

<script>
Array.prototype.contains = function(element)  {
   for(var i=0;i<this.length;i++) if(this[i] == element) return true;
   return false;
};

//INITIALIZE DATES ARRAY SAME AS YOU DID BEFORE
var dates = [];

function ProcessDates(){    
  //ADD YOUR PAGE LOAD CODE HERE
  //NOT USING THIS
}

</script>


<?php 
    include('connect-db.php');
    $sql = mysql_query("SELECT * FROM tbl_calendar") OR DIE(mysql_error());

    echo "<script type='text/javascript'>";

    //LOOP THROUGH DB RESULTS AND PUSH TO JAVASCRIPT ARRAY
    while($row = mysql_fetch_array($sql)) {
        echo "dates.push('$row[date]');";
    }

        //DATES ARRAY SETUP COMPLETE.  CALL FUNCTION TO PROCESS DATES
    echo "ProcessDates(); </script>";
?>

Upvotes: 1

Views: 287

Answers (1)

Adam Bergmark
Adam Bergmark

Reputation: 7536

Simply concatenate the name into the url as well, '<a href="page?date=' + today + '>' + today + '</a>'.

Upvotes: 1

Related Questions