Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1436
  • Last Modified:

Webpage error details on .js

trying to create a link on newform.aspx with this code attached. It's referenced on a CEWP on newform.aspx

Webpage error details

User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; InfoPath.2; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 1.1.4322; .NET4.0C; MS-RTC LM 8)
Timestamp: Thu, 17 Feb 2011 19:50:30 UTC

Message: 'length' is null or not an object
Line: 2
Char: 5
Code: 0
URI: http://servername/javascript/HyperlinkHandbook.js

What's fron with this code? many thanks
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.length - len)){
			return tags[i];
		return null;
var myLink = document.createElement('a');
// The contacts list is located in the same site on the same level  
// as the list for which the hyperlink is added to a column in 
// the NewForm.aspx page here 
myLink.href = "/hr/Shared%20Documents/Associate%20Handbook.pdf";
// Open the hyperlink in a new browser window = "_blank";
// Text of the hyperlink 
myLink.innerText = "Link to Handbook     ";
var theSelect=getTagFromIdentifierAndTitle("select","","Agreement");
// if theSelect is null, it means that the target list     
// has more than 20 items, and the Lookup is being 
//rendered with an input element     
	var theInput=getTagFromIdentifierAndTitle("input","","Agreement");
	// Add the previously created hyperlink in front
	//of the SharePoint column

Open in new window

1 Solution

I think you need to verify if your variable tags has found something.

    var len = identifier.length;
    var tags = document.getElementsByTagName(tagName);
    if (tags == null || tags == undefined) {
         // do something or simply get out of the function.
    for(var i=0; i < tags.length; i++) {
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now