1

Is it possible to check a querystring for a not null value using javascript? Can you show me an example on how to do this?

Like the IF clause of this snippet:

 protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["someParameter"]))
        {
            DataListWithLinksID.Attributes.Add("style", "display:none");
        }
    }

1 Answer 1

1

I use this

<html>
<head>
<script>
function parseQString() {
  var qs = new Array();
  var loc = location.search;
  if (loc) {
    loc = loc.substring(1); // lose the leading ?
    var parms = loc.split('&');
    for (var i=0;i<parms.length;i++) {
      nameValue = parms[i].split('=');
      qs[nameValue[0]]=(nameValue.length == 2)? unescape(nameValue[1]):null; // use null or ""
    }
  }
  return qs;
}
function getQSParm(parm) {
  return (qs[parm])?qs[parm]:null
}
var qs = parseQString();
// try getQstringValue.html?amount=23&emptyparm=&parmwithoutequals
alert(getQSParm("amount"));
alert(getQSParm("emptyparm"));
alert(getQSParm("parmwithoutequals"));

// your example:

window.onload=function() {
  if (getQSParm("someParameter")) {
      document.getElementById('DataListWithLinksID').style.display='none':
    }
}

</script>
</head>
<body>
</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.