Query Strings in Sitefinity w/ jQuery - Front- & Back-End Development - Front- & Back-End Development - Progress Community
 Front- & Back-End Development

Query Strings in Sitefinity w/ jQuery

  • Query Strings in Sitefinity w/ jQuery
  • 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'
        return cleanedString [1];
    //Note: I targeted the input box with a wrapped CSS class called '.productCodeWrap'. You can target this any way you wish!
        $(".productCodeWrap input.sfTxt").val();
        var value = unescape(getQuerystring('pid',''));
        if(value != 'null' && value != '')
          $(".productCodeWrap input.sfTxt").val(value);
          $(".productCodeWrap input.sfTxt").attr('readonly','true');
          );roductCodeWrap input.sfTxt").addClass("lockedField");

    Hope it helps someone! :)
  • This code is very interesting, I want to learn more about this :)