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">
_spBodyOnLoadFunctionNames.push("fillDefaultValues");
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_;
else
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;
}</script>
0 comments:
Post a Comment