Question : Javascript arrays

Hi,

I asked another question and got it solved so it's all good 9http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26308501.html)

However, I would like to make it more maintainable and tried to get rid of a lot of code and store url's and links in different arrays and then append them depending on querystring id, it breaks though.

What I have done so far:

function gup( filter )
{
  filter = filter.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+filter+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}

queryString = gup("SelectedID");

var filter = new array(10);
filter[1] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=Roads';
filter[2] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=National%20Rail';
filter[4] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=Branch%20Services';
filter[5] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=Finance%20and%20Commercial';
filter[7] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=Strategic%20Development';
filter[9] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=Shared%20Services';
filter[10] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=NSW%2FACT%20Business';
filter[11] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=General%20Manager';
filter[12] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=BMT';
filter[14] = '&FilterField1=Responsible%5Fx0020%5FBusiness&FilterValue1=New%20Zealand';

var url = new array(4);
url[0] = 'https://xy.com//Individual%20Item%20Counts.aspx?View={45549A90-A8C3-4993-9A03-D60F1ACD8DE0}';
url[1] = 'https://xy.com/Individuals%20Modified%2030.aspx?View={BE6BD726-EF0D-498F-B58F-B1C1DDF732CD}';
url[2] = 'https://xy.com/Individuals%20Completed%20Last%2030.aspx?View=%7B9A3D27FE%2D5C2E%2D411B%2DA637%2DA57C886832B4%7D';
url[3] = 'https://xy.com/Individual%20Items%20Due%20Next%2030.aspx?View={BB509B57-A0A4-4C3C-9144-2023C42BE2E5}';

var goPage=new Array(4);

if (queryString == "")
{
goPage[0]='https://xy.com/Individual%20Item%20Counts.aspx';
goPage[1]='https://xy.com/Individuals%20Modified%2030.aspx';
goPage[2]='https://xy.com/Individuals%20Completed%20Last%2030.aspx';
goPage[3]='https://xy.com/Individual%20Items%20Due%20Next%2030.aspx';
}

else
{
goPage[0]= url[0] + filter[queryString];
goPage[1]= url[1] + filter[queryString];
goPage[2]= url[2] + filter[queryString];
goPage[3]= url[3] + filter[queryString];
}

I tried to convert the querystring value to int but it didn't work, any other suggestions?

Thanks in advance.

Answer : Javascript arrays

>> I commented it out as I then used the formula
That is the problem then.
The function returns a STRING, which is some textual data.  But from what you are saying, you actually want a function that returns a DATE or DOUBLE to be used in calculations.

As it stands, the function would be useful for somewhat formatting and displaying time data.

Here's just a quick test with time:
Enter into these cells on a new sheet:
A1:  12:23
B1:  13:23
C1:  =A1-B1
D1:  13:44
E1:   =D1+C1

You will notice that even if you made column C really wide, Excel cannot display -1hr.  BUT, change the formatting to General and you will see that the DOUBLE value representing -0.04167 of a day is stored there.  It also correctly calculates E1.

Hopefully that helps some in your understanding.

For your formula, try this:

=IF(C2>=$M$1,C2-$M$1,IF(C2=TIME(0,1,0),1-(Time(0,0,0)-$M$1),1-(C2-$M$1)))

It may be possible to further simplify, but I took out the function and changed "24:00" to the numeric value 1.
Random Solutions  
 
programming4us programming4us