2
<div id="main">
<div class="navigate">
    <ul>
        <li>
            <a href="http://localhost/xm/index.php"><span>xm</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin"><span>Admin</span></a> &#187;
        </li>
        <li>
            <a href="http://localhost/xm/index.php?action=admin;change=name;random02342=randomvaluetoo320230"><span>change</span></a>
            .......

From this html code I have to get random generated data "random02342=randomvaluetoo320230" in variable, which is random generated both random0234 and random value too. How I can achieve this via Javascript (jquery or not)?

EDIT: random02342 and randomvaluetoo320230 is randomly server-side generated.. so its like every time new hash like 1stHash4324kjkjdas324324=And2ndAnotherHash324324asd23432

  • Did these values have pattern, e.g. if it always starts with 'random'? Or does it always have three query params? Do you know all other params in query string? – Felix Oct 01 '12 at 00:14
  • All other i know and third is only randomly generated like ?action=admin;change=name;1stHASH=2ndHASH and there is always '=' between. – Petar Bojić Oct 01 '12 at 00:22

3 Answers3

2

This would get it, though it's probably not going to win any awards for elegance:

var m = document.getElementById('main').innerHTML.match(/random(\d+)=randomvaluetoo(\d+)/);
// m[1] and m[2] are the two random values.
Niet the Dark Absol
  • 301,028
  • 70
  • 427
  • 540
0
var first, second;

var q = $('.navigate ul li a[href*="change=name"]').attr('href').split(';').filter(
    function() {
        return this.contains('random');
    }
).join().replace(/[a-zA-z]/g, '').split('=');

first = q[0];
second = q[1];
nbrooks
  • 17,489
  • 5
  • 46
  • 61
0

based on your comment:

var value = $('selector').attr('href').split(';')[2].split('=');

this will give you value[0] - name, and value[1] - value However this is only if there 3 query params and the random one is the third

Also this might be usefull Parse query string in JavaScript

Community
  • 1
  • 1
Felix
  • 810
  • 10
  • 17
  • You're welcome, really not good solution tho... it would be good to think about to refactor this – Felix Oct 01 '12 at 01:19