0

I have one string

var str = '';
str += 'category='+jv('category')+'&';

str += 'refresh_rate='+jv('refreshRate')+'&';

str += 'submit=Y';

now I want to take values from jv('category') and jv('refreshRate') in separate string in javascript (I want to extract values after "=" and before "&").

Thanks.

Daniel Vandersluis
  • 91,582
  • 23
  • 169
  • 153
rajesh
  • 1,413
  • 2
  • 17
  • 23
  • Question is unclear. What is `jv`, and where is the category and refreshRate value coming from? – Anurag Aug 23 '10 at 06:19
  • jv is like this function jv(divid){if(document.getElementById(divid)) return document.getElementById(divid).value; } – rajesh Aug 23 '10 at 06:45

2 Answers2

0

You can use http://github.com/allmarkedup/jQuery-URL-Parser or any other URL parser for this sort of string.

Māris Kiseļovs
  • 16,957
  • 5
  • 41
  • 48
0

I've used this: http://blog.stevenlevithan.com/archives/parseuri URI Parser in the past and find it simple to use and it doesn't rely on any other libraries. Its also pretty lightweight.

The author has a demo page but doesn't really explain how to use it.. Its really simple, you just do something like this:

var url = "http://my-site.com:8081/index.html?query=go&page=2";
var parsed = parseUri(url);

From there you can get things like the host/protocol/port/etc.. When dealing with the querystring you do

var page = parsed.queryKey.page;
alert(page); //alerts 2

Click the parse button on the demo page to see all properties of the parsed URI object that you can access..

Matt Wolfe
  • 8,924
  • 8
  • 60
  • 77