More in this section
Forums / Developing with Sitefinity / Query Strings in Sitefinity w/ jQuery

Query Strings in Sitefinity w/ jQuery

The forums are in read-only mode. In case that you want to directly contact the Progress Sitefinity team use the support center. In our Google Plus group you can find more than one thousand Sitefinity developers discussing different topics. For the Stack Overflow threads don’t forget to use the “Sitefinity” tag.
2 posts, 0 answered
  1. Jay
    Jay avatar
    1 posts
    Registered:
    09 Feb 2012
    19 Apr 2012
    Link to this post
    Just a solution that I hope will help others in passing in query strings into forms in Sitefinity.
    In this example a user clicks on a button to enquire about a particular product - The product code is passed via query string into a form.
    Form field remains locked if a value is successfully passed and unlocked/empty if no query string is picked up.

    Feel free to add any recommendations/modifications to this:

    // This method retrieves the querystring value. If the querystring is missing it returns null. I’m not the author of the method :)
    function getQuerystring(key, default_) {
      if (default_==null) default_="";
      key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
      var cleanedString = regex.exec(window.location.href);
      
      if(cleanedString == null)
        return 'null'
      else
        return cleanedString [1];
    }
     
    //Note: I targeted the input box with a wrapped CSS class called '.productCodeWrap'. You can target this any way you wish!
    $(document).ready(function() {
        $(".productCodeWrap input.sfTxt").val();
        var value = unescape(getQuerystring('pid',''));
        if(value != 'null' && value != ''){
          $(".productCodeWrap input.sfTxt").val(value);
          $(".productCodeWrap input.sfTxt").attr('readonly','true');
          $(".p
         
          });roductCodeWrap input.sfTxt").addClass("lockedField");
        }

    Hope it helps someone! :)
  2. Sheena
    Sheena avatar
    11 posts
    Registered:
    24 Sep 2012
    24 Sep 2012
    Link to this post
    This code is very interesting, I want to learn more about this :)
2 posts, 0 answered