Click here to Skip to main content
15,942,847 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have created 3 JavaScript Functions. The 1st 2 will return 2 values and I want the 3rd function to grab those values.

JavaScript
function retStartDate(){
var strStartDate = document.getElementById("from_date").value;
alert(strStartDate);

return strStartDate;

}

function retEndDate(){
var strEndDate = document.getElementById("to_date").value;
alert(strEndDate);
return strEndDate;

}

function getVaria(){

var strWsUrl = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date= retStartDate() &end-date= retEndDate() &max-results=10';

alert(strWsUrl);

return strWsUrl;

}


Now you can see getVaria() has a variable strWsUrl & in that I have placed the 2 functions that return strStartDate & strEndDate as the below.

JavaScript
var strWsUrl = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date= retStartDate() &end-date= retEndDate() &max-results=10';


But when I alert that I got the follwoing result.

https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date= retStartDate() &end-date= retEndDate() &max-results=10

But the correct alert must be with two dates for start-date & end-date.

Can you someone guess what I have done wrong? If so please try to post the solution.

Thanks & regards,
Chiranthaka.
Posted

1 solution

Hi Sampath,

It is because you are not calling your javascript functions.The alert shows your strWsUrl as it is.So, you can do something like this.Call two of your javascript functions like below

C#
function getVaria(){

var strWsUrl = 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date= '+ retStartDate() + '&end-date=' + retEndDate() + '&max-results=10';

alert(strWsUrl);

return strWsUrl;

}


Hope this help :-)
 
Share this answer
 
v2
Comments
Chiranthaka Sampath 22-Jul-14 2:50am    
Ok it worked fine.
Dilan Shaminda 22-Jul-14 2:55am    
Nice :-) Could you please accept the answer if it works for you

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