I am working with the below Javascript function. It only works when the value is a number. I mean it only returns the value if it is a a number. For example:
var ldInstID = getParameterByName("ID")
If ID
is a number then it works and assigns the value to the variable but if the ID
is a string it is not working. Please help to make this work for a string too.
I am using this on SharePoint list edit page where ID is a list column value. I want to capture another column city and pass it as href query string along with ID.
In the attached images you can see that ldInstID is blank
<!--
Name: dispParent.js
-->
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
jQuery(document).ready(function($) {
//get the ID for the Issue from the Query String
// var issueID = getParameterByName("ID");
var ldInstID = getParameterByName("LeadInsitution");
//find the element with the "Add new item" link.
//note that if you have more than one list on your page, this just finds the first one
var anchorElement = $("a[title='Add a new item to this list or library.']");
//modify the "Add new item" link to call the "NewItem2" function and pass in the Issue ID.
//Be sure to put the path to your site below. You can use relative URL to the web application or the FQDN
// $(anchorElement).attr("href","javascript:NewItem2(event,'URL/Lists/Time/NewForm.aspx?IssueID=" + issueID + "');");
// $(anchorElement).attr("href","javascript:NewItem2(event,'URL/NewForm.aspx?IssueID=" + issueID + "&LdInst" + LdInst + "');");
$(anchorElement).attr("href","javascript:NewItem2(event,'URL/NewForm.aspx?LdInstID=" + ldInstID + "');");
//remove the "onclick" attribute from the anchor element as we aren't using it anymore
$(anchorElement).removeAttr("onclick");
});
// no, I didn't write this function from scratch, I found it at
// http://stackoverflow.com/questions/901115/get-query-string-values-in-javascript
// http://www.sharepointhillbilly.com/Lists/Posts/Post.aspx?ID=26
function getParameterByName(name)
{
name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
var regexS = "[\\?&]" + name + "=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);
if(results == null)
return "";
else
return decodeURIComponent(results[1].replace(/\+/g, " "));
}
</script>