How to get Querystring value from the url in a listform in SharePoint

Here is a code snippet to get a querystring value from the url, say from any listform and populate the existing choice field in the form.

<script type="text/javascript">


function fillDefaultValues()

var choiceField = getTagFromIdentifierAndTitle("select","DropDownChoice","Action Type");

if(choiceField != null)
var _value = getQuerystring("QueryStringvalue");
choiceField.value = _value;

function getQuerystring(key, default_)
if (default_==null) default_="";
key = key.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regex = new RegExp("[\\?&]"+key+"=([^&#]*)");
var qs = regex.exec(window.location.href);
if(qs == null)
return default_;
return qs[1];

function getTagFromIdentifierAndTitle(tagName,identifier,title)

var len=identifier.length;
var tags=document.getElementsByTagName(tagName);
for(var i=0;i<tags.length;i++)

var tempString=tags[i].id;

if(tags[i].title==title && (identifier=="" ||

tempString.indexOf(identifier)==tempString.length - len)){

return tags[i];



return null;



Post a Comment

Popular Posts