Click here to Skip to main content
15,947,958 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more: , +
I have the following URL

C#
var googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+
    'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=2014-04-09&end-date=2014-04-23&max-results=10';


In that URL there are 2 variables &start-date and &end-date.

The values for that 2 variables are hard coded, but what I want is from an HTML form I want to send 2 date values to that particular URLs' start-date & end-date. I am trying to do that using only JavaScript. If JS is not capable show me how to do that?

Thanks & regards,
Chiranthaka
Posted
Updated 9-Jul-14 18:49pm
v2

1 solution

Hi,

Put both date values in two variables in JS function.
Then Use


JavaScript
var googleURL = "https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date='"+Date1+"'&end-date='"+Date2+"'&max-results=10;'"


Pls check by using this, then tell me it is solved or not.
 
Share this answer
 
Comments
Chiranthaka Sampath 16-Jul-14 3:41am    
I did that and still the variables are not assigned to the URL. when I alert the googleURL variable the start-date & end-date are displayed as 'undefined' see it below.

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=undefined&end-date=undefined&max-results=10

So what do you think that what I have to do?

Thanks & regards,
Chiranthaka
Sarvesh Kumar Gupta 16-Jul-14 5:01am    
In javascript, first find control start date and end date. then find value and put in url.
Please give your full JS code
Chiranthaka Sampath 16-Jul-14 5:53am    
This is the full source code.

<script type="text/javascript" >


var strStartDate;
var strEndDate;
var googleURL;

//The following JS function will pass the values from the form to the URL.
function passVariable() {

strStartDate = document.getElementById("from_date").value;
strEndDate = document.getElementById("to_date").value;

alert(strStartDate);
alert(strEndDate);
//alert(googleURL);
document.write(googleURL);

}

googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=' + strStartDate + '&end-date=' + strEndDate + '&max-results=10';

passVariable();
Sarvesh Kumar Gupta 16-Jul-14 6:02am    
It's Wrong

function passVariable() {
strStartDate = document.getElementById("from_date").value;
strEndDate = document.getElementById("to_date").value;

alert(strStartDate);
alert(strEndDate);
//alert(googleURL);
googleURL = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions='+'ga%3Asource&metrics=ga%3Ausers&sort=-ga%3Ausers&start-date=' + strStartDate + '&end-date=' + strEndDate + '&max-results=10';
document.write(googleURL);
}

call this function at any event
Chiranthaka Sampath 16-Jul-14 6:12am    
OK pal I use the solution you have provided & it works like a charm. Thank you very much.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900