Pages

Wednesday, July 6, 2011

sharepoint 2010 Javascript Function to acess the Control

Here is a Javascript Function to acess the Control.
tagName – The name of the tag rendered in the form’s HTML
identifier – The string associated with the SharePoint type of the relevant ield
title – The value of the relevant HTML tag’s “title” attribute, which also matches the field’s display name

ref from:http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx

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 you are not sure what the actual title of your field is, uncomment this alert 
          //alert(tags[i].title); 
          if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len)) { 
               return tags[i]; 
          } 
      } 
      return null; 
}
for eg: if you control rendered as(Use FireBug or Devlopers Tool)
"input type="text" autopostback="0" class="ms-input" title="Calendar2" id="ctl00_m_g_267b3037_41f7_4630_8946_1f2378ebeda2_ctl00
_ctl05_ctl03_ctl00_ctl00_ctl04_ctl00_ctl00_DateTimeField_
DateTimeFieldDate" 
maxlength="45" name="ctl00$m$g_267b3037_41f7_4630
_8946_1f2378ebeda2$ctl00$ctl05$ctl03$ctl00$ctl00$ctl04$ctl00$ctl00
$DateTimeField$DateTimeFieldDate"
Here
Tag Name: is input
Title: is Calendar2
Identifier: is DateTimeFieldDate

No comments:

Post a Comment