SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Replace value of QueryString parameter

    Hello,

    I would like to replace the value of a querystring parameter with javascript. Something like:

    Code:
    URL: http://localhost/Europe.asp?group=Europe&region=Italy&pview=25&page=1
    I want to change the value of pview. I think I just need some Regular Expression to match the pview=? (any number)

    Code:
    var qs = new String(window.location);
    alert(qs.replace(someregexp,'pview='+newval));
    Thanks,
    vc

  2. #2
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    var reExp = /pview=\d+/;
    var url = window.location.toString();
    var newUrl = url.replace(reExp, "pview=" + newValue);

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Worked perfectly. Thank you.

    Regular expressions drive me nuts.

  4. #4
    SitePoint Wizard Pepejeria's Avatar
    Join Date
    Jan 2005
    Location
    Too far up north
    Posts
    1,566
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, they can drive u nuts, but they are extremely powerful.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •