-4

My url will have querystring like the following

TestPage.aspx?s=bcs_locations&k=userkwd* bcslocationtype:"Hospital"

where ?s=bcs_locations will always be the same. there are three checkboxes and an inputbox for user input. If user only checks checkboxes, the url will look like this:

TestPage.aspx?s=bcs_locations&k=bcslocationtype:"Hospital"

If user only types in sth in inputbox, url will be like this:

TestPage.aspx?s=bcs_locations&k=vincent*

if user checks some checkbox and also types in keyword in the inputbox, URL will look like

TestPage.aspx?s=bcs_locations&k=userkwd* bcslocationtype:"Hospital"

'Hospital' etc is the value of selected checkbox.

Now I only need to grab anything infront of * and k=, if ever * exists in the URL?

I can get the querystring like this:

  var val=window.location.href.match(/[?&]k=([^&#]+)/) || []; 
if (value.length == 2) { 

 valuesafterK=value[1];
 //i now need values after k= and * if there * in value[1]
}
user229044
  • 232,980
  • 40
  • 330
  • 338
Anjana Sharma
  • 4,535
  • 5
  • 37
  • 51
  • This is a duplicate of this question... - http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript – bytebender Mar 01 '12 at 18:00
  • @Sarika, you need to login as 'Anjana Sharma'. Log out of this current account, and login into your other account, you will be able to see the tick button – DG3 Mar 01 '12 at 18:00
  • @Sarika: you do know that your URLs are invalid, right? neither spaces nor * nor " are legal characters in the query string. – rodneyrehm Mar 01 '12 at 18:02
  • Sharepoint is fine with that pattern – Anjana Sharma Mar 01 '12 at 18:24
  • I merged this account with the one that posted http://stackoverflow.com/questions/9520157/set-checkboxes-checked-after-page-refresh-based-on-checkboxes-values-in-the-url. You should be able to accept the answer there now. – Michael Myers Mar 01 '12 at 20:59

1 Answers1

0

You can use this function.

function queryString(key) {
    var query = window.location.search.substring(1);
    var vars = query.split('&');
    for (i = 0; i < vars.length; i++) {
        var cVar = vars[i].split('=');
        if (cVar[0] == key) {
            return cVar[1];
        }
    }
}

var k = queryString('k');
arunes
  • 3,464
  • 2
  • 21
  • 31