SD1990
SD1990

Reputation: 808

calling a javascript function to output the url into ruby/html

When the page loads i need the application to load a javascript function that displays a part of the url. Ive can get as far as to display the dates i want at the right times by using a button and alert. But what i want to do is to have the date display in a span tag by calling the function.

my js function for getting the date.

function getURL(){
    var url = document.location.href;
    urlSplit = url.split("/timesheet");

    if(urlSplit[1]== "")
    {
        var d = new Date();
        //return d.toString;
        alert(d);
    }
    else
    {
        week = url.split("week_commencing=");
        //return week[1];
        alert(week[1]);
    }
}

my span tag

<b><center>Hours for Week commencing: <span id="startDate"></span></center></b><br />

Im sure this is really simple but its proving to be extremely tricky. Can anyone point me in the right direction?

Upvotes: 0

Views: 199

Answers (1)

AmGates
AmGates

Reputation: 2123

Just call document.getElementById("startDate").innerHTML = date in place of the alert.

regards

Upvotes: 1

Related Questions