1

I'm calling the (fairly old) plugin "thickbox" as described here:

<input type="text" id="RecordType" size="10">
<a id="RecSubTypeHref" href="index.pl?img=true&type=RecSubType" class="thickbox" disabled title='Title goes here'><img border=0 src='images/questionmark.png'></a>

When the thickbox is created it contains a list of stuff based on the query.

Using JavaScript or jQuery I'd like to be able to access the value of type (in the example above type=RecSubType).

Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
martok
  • 479
  • 2
  • 6
  • 11

1 Answers1

0
// Adapted from http://tinyurl.com/pqxtu2
function getQuerystring(url, key, default_)
{
  if (default_==null) default_="";
  key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
  var qs = regex.exec(url);
  if(qs == null)
    return default_;
  else
    return qs[1];
}

var href = $('a#RecSubTypeHref')[0].href;
console.log(getQuerystring(href, 'type'));

Live demo.

Too easy ;)


(Also see How can I get query string values in JavaScript? for more handy query string parsing approaches.)

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055