I have hopefully a relatively straight forward one for you guys. Unfortunately not so straight forward for me.

I have a an existing java script that works with a group of checkboxes that I have. Its quite simple, If you select a checkbox and click submit the javascript function will open a URL link in the using the checkbox input value. If I tick multiple boxes and click submit, all the links are open at the same time. The code works very well.

What I want to do now is incorporate a Select list with date ranges i.e. Last Month, This Month, January, February, March, April up to December.... What I need to be done for example is if I select "Last Month" then tick a checkbox and submit it should open the link in the Input Value + "?pv0=" first day of last month + "&pv1=" last day of last month

Example of resulting full link would like like this: na6.salesforce.com/00O80000004z1VC?pv0=01/01/2014&pv1=01/31/2014

The links I have in the checkbox input Values are like so na6.salesforce.com/00O80000004z1VC

Each checkbox has a unique value, however, the base domain is always the same na6.salesforce.com/

The date order should be mm/dd/yyyy

Here is my current Javascript code (which i need the select list incorporated into):

<script type="text/javascript">

function submit()
{
//alert("i am in");
var data = document.forms[0].sfdcbox;
var i;
for (i=0;i<data.length;i++)
 {
if (data[i].checked)
{
window.open(""+data[i].value);
}
}
}

</script>
enter code here

<form method="POST">
<input type="checkbox" name="sfdcbox" value="na6.salesforce.com/00O80000004z0VQ?csv=1"><label>Cases Closed & Avg</label><br/>
<input type="checkbox" name="sfdcbox" value="na6.salesforce.com/00O80000004z0WY?csv=1"><label>Emails Sent</label><br/>
<input type="checkbox" name="sfdcbox" value="na6.salesforce.com/00O80000004z0WO?csv=1"><label>Activities</label><br/>
<input type="checkbox" name="sfdcbox" value="na6.salesforce.com/00O80000004z0XC?csv=1"><label>KB Linking</label><br/>
</form>
<input type="button" value="Run" onclick="submit()">

The Select Field
Select Report Period: 
<select name="sfdcfilter" id="Range" style="width:130px">
<option value="LastMonth">Last Month</option>
<option value="ThisMonth">This Month</option>
<option value="0">January</option>
<option value="1">February</option>
<option value="2">March</option>
<option value="3">April</option>
<option value="4">May</option>
<option value="5">June</option>
<option value="6">July</option>
<option value="7">August</option>
<option value="8">September</option>
<option value="9">October</option>
<option value="10">November</option>
<option value="11">December</option>
</select>

Here is my failed attempt at the script

<script type="text/javascript">

function submit()
{

var option=document.getElementById('Range').value;
if(option=="LastMonth"){
  datestart = new Date(today.getFullYear(), today.getMonth()-1, 1);
  dateend = new Date(today.getFullYear(), today.getMonth(), 1);
 } else if(option=="ThisMonth"){
 datestart = new Date(today.getFullYear(), today.getMonth(), 1);
 dateend = new Date(today.getFullYear(), today.getMonth() + 1, 1);
    } else {
  if (option > today.getMonth()) { 
    year = today.getFullYear() - 1;
  } else {
    year = today.getFullYear();
  }
  datestart = new Date(year, option, 1);
  dateend = new Date(year, parseInt(option) + 1, 1);
}

start = ('0' + (datestart.getMonth()+1)).slice(-2) + '-' + ('0' + datestart.getDate()).slice(-2) + '-' + datestart.getFullYear();
end =  ('0' + (dateend.getMonth()+1)).slice(-2) + '-' + ('0' + dateend.getDate()).slice(-2) + '-' + dateend.getFullYear();

//alert("i am in");
var data = document.forms[0].sfdcbox;
var i;
for (i=0;i<data.length;i++)
  {
  if (data[i].checked)
    {
    window.open(""+data[i].value + "&pv0=" + start + "&pv1=" + end);
   }
  }
}

</script>

FYI - the checkbox values all contain "https:// at the front but i left them out so i dont get in trouble

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.