Category Archives: Requests

Get field value for all SharePoint FieldTypes or set field as read only in EditForm

16.10.2010 The function getFieldValue is posted in another – more updated – version here.

29.04.2010 Updated the code for the file “GetFieldValueOrSetAsReadonly.js” to support “SPFieldUserMulti” and for getting the field value in DispForm.


I have had several requests for a solution for setting fields as read only in EditForm. I have created this script to achieve this.

This script enables you to get the field value for any SharePoint field type in EditForm, and to set the field as read only by grabbing it’s value, hiding the <TD>, and adding a clean <TD> with the value in it’s place.

As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
IMG

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.4.2.min. If you use another version, please update the reference in the code.

Read here how to add a CEWP to EditForm, and how to get the FieldInternalNames for your fields.

Add this code to a CEWP below the EditForm:

&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/GetFieldValueOrSetAsReadonly.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Array of FieldInternalNames to make readonly
var arrToMakeReadOnly = ['Title','MySelect','MyPeoplePicker','Lookup','Bool','Hyperlink','DateTime','Multiline'];

// The function call must be wrapped in the &quot;$(document).ready&quot; to work with complex field types
$(document).ready(function(){
	readOnlyFieldArray(arrToMakeReadOnly);
});
&lt;/script&gt;

The above code sets all fields in the array “arrToMakeReadOnly” as readonly. To simply get a fields value, do it like this:

&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/GetFieldValueOrSetAsReadonly.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

// The function call must be wrapped in the &quot;$(document).ready&quot; to work with complex field types
$(document).ready(function(){
	var myValue = getFieldValue(&quot;Insert the FieldInternalName of your field here&quot;);
});
&lt;/script&gt;

To get a fields value in DispForm, do it like this:

&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/GetFieldValueOrSetAsReadonly.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

	var myValue = getFieldValue(&quot;Insert the FieldInternalName of your field here&quot;,&quot;disp&quot;);

&lt;/script&gt;

The sourcecode for the file “GetFieldValueOrSetAsReadonly.js”:

/* Get field value for all field types, or set as readonly in EditForm 
 * ---------------------------------------------
 * Created by Alexander Bautz
 * alexander.bautz@gmail.com
 * https://spjsblog.com
 * v1.1
 * LastMod: 29.04.2010
 * LastChange: Supporting &quot;SPFieldUserMulti&quot; and for getting the field value in DispForm
 * ---------------------------------------------
 * Include reference to jquery - http://jquery.com
 * ---------------------------------------------
 * Call from a CEWP below the list form in EditForm like this:
	&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/readOnlyForSharepointFields.js&quot;&gt;&lt;/script&gt;
	&lt;script type=&quot;text/javascript&quot;&gt;
	// Array of FieldInternalNames to make readonly
	var arrToMakeReadOnly = ['Title','MySelect','MyPeoplePicker','Lookup','Bool','Hyperlink','DateTime','Multiline'];
	
	// The function call must be wrapped in the &quot;$(document).ready&quot; to work with complex field types
	$(document).ready(function(){
		redOnlyField(arrToMakeReadOnly);
	});
	&lt;/script&gt;
*/

function readOnlyFieldArray(arrayOfFieldInternalNames){
	$.each(arrayOfFieldInternalNames,function(i,fin){
		var fieldValue = getFieldValue(fin);
		if(!fieldValue)return false;
		thisField=$(fields[fin]);
		// Strip off any &quot;formvalidation star&quot;		
		thisField.find('.ms-formlabel span.ms-formvalidation').remove();
		// Set as &quot;readOnly&quot;
		thisField.find('td.ms-formbody').hide().after(&quot;&lt;td class='ms-formbody' style='width:450px'&gt;&quot;+fieldValue+&quot;&lt;/td&gt;&quot;);
	});
}

function getFieldValue(fin,edit_OR_disp){
// If not already done - init all fields
if(typeof(fields)=='undefined')fields = init_fields();
// Return if FieldInternalName is not found
if(fields[fin]==undefined)return;
var thisField = $(fields[fin]);
// If &quot;edit_OR_disp&quot; is undefined, default to &quot;edit&quot;
if(edit_OR_disp==undefined)edit_OR_disp='edit';
	if(edit_OR_disp=='disp'){ // If &quot;disp&quot;
		var valRaw = $(fields[fin]).find('.ms-formbody').text();
		return (valRaw.replace(/[ xA0]+$/,'')=='')?'':valRaw.replace(/[ xA0]+$/,'');
	}else{ // If &quot;edit&quot;		
		var fieldType = $(fields[fin]).attr('FieldType');
		if(fieldType==undefined){
			alert(&quot;The attribute &quot;FieldType&quot; is missing.nEnsure the function init_fields() used is the one included in the file &quot;GetFieldValueOrSetAsReadonly.js&quot;.&quot;);
			return false;
		}
		returnVal = '';		
		switch(fieldType){
			case 'SPFieldText':
			case 'SPFieldNumber':
			case 'SPFieldCurrency':
				returnVal = thisField.find('input').val();
			break;
			case 'SPFieldChoice':
				if(thisField.find('input:radio').length&gt;0){
					returnVal = thisField.find('input:radio:checked').next().text();
				}else{
					returnVal = thisField.find('select').val();
				}
			break;
			case 'SPFieldMultiChoice':
				var multiChoice = [];
				thisField.find('input:checkbox:checked').each(function(i,opt){
					opt = $(opt);
					multiChoice.push(opt.next().text());
				});
				returnVal = multiChoice.join('&lt;br /&gt;');
			break;
			case 'SPFieldUser':
				var myPeoplePicker = thisField.find(&quot;div[id='divEntityData']&quot;);
				returnVal = myPeoplePicker.attr('displaytext');
				returnVal = (returnVal!=undefined)?returnVal:'';
			break;
			case 'SPFieldUserMulti':
				var userMulti = [];
				thisField.find(&quot;div[id='divEntityData']&quot;).each(function(i,div){
					thisVal = $(div).attr('displaytext');
					if(thisVal!=undefined){
						userMulti.push(thisVal);
					}				
				});
				returnVal = userMulti.join('&lt;br /&gt;');
			break;
			case 'SPFieldLookup':
				if(thisField.find('select').length&gt;0){
					returnVal = thisField.find('select option:selected').text();
				}else{
					returnVal = thisField.find('input').val();
				}
			break;
			case 'SPFieldLookupMulti':
				var lookupMulti = [];
				thisField.find(&quot;select:last option&quot;).each(function(i,opt){
					opt = $(opt);
					lookupMulti.push(opt.text());
				});
				returnVal = lookupMulti.join('&lt;br /&gt;');
			break;
			case 'SPFieldBoolean':			
				returnVal = (thisField.find('input').attr('checked')==true)?true:false;
			break;
			case 'SPFieldURL':
				var link = thisField.find('input:first').val();
				var descr = thisField.find('input:last').val();
				returnVal = &quot;&lt;a href='&quot;+link+&quot;'&gt;&quot;+descr+&quot;&lt;/a&gt;&quot;;
			break;
			case 'SPFieldDateTime':
				var date = thisField.find('input:first').val();
				var hour = thisField.find('select:first option:selected').val()
					hour = (hour==null)?'':hour.match(/^[d]+/)+&quot;:&quot;;
				var AMPM = thisField.find('select:first option:selected').val()
					AMPM = (AMPM==null)?'':AMPM.match(/AM|PM/);
				var minutes = thisField.find('select:last option:selected').val();
					minutes = (minutes==null)?'':minutes;
				returnVal = date+&quot; &quot;+hour+minutes+&quot; &quot;+AMPM;
			break;
			case 'SPFieldNote':
				returnVal = thisField.find('textarea:first').val();
			break;
			case 'customHeading':
				returnVal = '';
			break;
			default:			
			returnVal = &quot;Unknown fieldType: &lt;strong&gt;&quot;+fieldType+&quot;&lt;/strong&gt;, please check the script.&quot;;
		}
		if(returnVal==='')returnVal=&quot;&amp;nbsp;&quot;;
		return returnVal;
	}		
}

function init_fields(){
	var res = {};
	$(&quot;td.ms-formbody&quot;).each(function(){
	var myMatch = $(this).html().match(/FieldName=&quot;(.+)&quot;s+FieldInternalName=&quot;(.+)&quot;s+FieldType=&quot;(.+)&quot;s+/);	
		if(myMatch!=null){
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var type = myMatch[3];
			if(type=='SPFieldNote'){
				if($(this).find('script').length&gt;0){
					type=type+&quot;_HTML&quot;;
				}
			}
			if(type=='SPFieldLookup'){
				if($(this).find('input').length&gt;0){
					type=type+&quot;_Input&quot;;
				}
			}
			// Build object
			res[fin] = this.parentNode;
			$(res[fin]).attr('FieldDispName',disp);
			$(res[fin]).attr('FieldType',type);
		}		
	});
	return res;
}

Save as “GetFieldValueOrSetAsReadonly.js”, mind the file extension, and upload to the scriptlibrary as shown above.

Note!
The function init_fields() used in this code is the new one posted here: Revised function init_fields()

It has additional functionality not found in previous versions. Be sure to update the function if adding this to existing code.

Ask if anything is unclear

Regards
Alexander

Filter a calendar view based on user profile property

I got this request from Carel Schotborgh:

Using WSS 3.0

Not have been able to find it anywhere so, since it is possible to filter a list items (in all event/task/etc view) based on membership in SharePoint group (By Alexander). I would like to request the possibility to filter an Agenda View on a single line text, based on a field of the current user information field (for instance department). I import data into SharePoint list what contains names of people. So users do not create the list items and there are multiple columns with names like Judge1 Judge2 Lawyer etc. As you all know you can’t use [ME] value in a single line text. This can only be used with columns: Created by, Modified by, Assigned to and People picking data. Problem with agenda view is also that it only displays 1 field (in general description of appointment for instance).

What do I want?
Filter (a) specific column(s) on the basis of the current user that is logged on (department field for example) in an agenda view.

The agenda should only show items that match the same text as entered in the department field of the user information field of the user that is currently logged on.

In my case IF Judge1 = Mr. J. Jenkins display it OR IF Judge2 = Mr. J. Jenkins display it. The OR statement is very important since SharePoint also filters with AND statement. So I would like to filter multiple columns with department field (any other also ok, as long I can fill in a value that is connected to the current user).

I already managed to create something that filters all event/tasks/etc list view, searching all the columns based upon the current user department field with or statement idea, but not specific columns. Also in agenda view my code and Alexanders code will not work.

If it is not possible to do this on each specific column it is also ok to search all of the columns since the names in my list are unique for each column. Other columns do not contain their names in such a way anyway. I’m already using my script for the not agenda view and works perfectly except user with slow internet will see the entire list my filter starts working.

Excuse me for long text, but it is complex. Much appreciated any help, suggestion or solution.


Here is one suggestion on how this can be done. It pulls the “Department” from the user profile and searches for a match in one of the fields specified in the script (in the variable “arrOfFieldInternalNames”).

This solution does:

  • Filters a calendar view based on a text retrieved from the current users profile (from People and Groups)
  • Filters with an “OR” statement looking for a match in multiple text fields
  • Handles “single day items” and items spanning over multiple days.
  • Hide the calendar view until it has been filtered

This solution doesn’t:

  • If multiple elements are located in one day, the standard calendar view will display a “x more items” link to expand all items that day. My filter solution will filter the items, but may display a link saying there are “3 more items”, but when clicking the link there may no items to display.

The solution
To keep a nice even background when removing items spanning over multiple days, i had to change the background for the “not in this month items” to white.

Add this code to a CEWP below the calendar view:

&lt;style type=&quot;text/css&quot;&gt;
.ms-cal-nodataMid,.ms-cal-nodataBtm2{
	background-color:#FFFFFF;
}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/interaction.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/stringBuffer.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;

// Set variables
listGuid = 'FilterCalendarView'; // Use list Name or List Guid
listBaseUrl = L_Menu_BaseUrl;
userListGuid = &quot;{570D772F-0EAB-45A8-8C54-9CCD4EC6A0AF}&quot;; // The &quot;People and Groups&quot; list
userListBaseUrl = ''; // Modify if on a managed path
// The FieldInternalNames to search for information matching the selected user property
arrOfFieldInternalNames = ['Judge1','Judge2'];

// Hide calendar view until it is filtered
$(&quot;.ms-cal-gempty&quot;).hide();

// Get the UserInfo
var userInfoObj = getUserInfo();
var dep = userInfoObj.Department; // User profile property &quot;Department&quot;

// Find all &quot;relevant&quot; items
var myItems = getMyItemsID(dep,arrOfFieldInternalNames);
// Filter view
filterCalendarView(myItems);

function getMyItemsID(find,findInArr){
	wsBaseUrl = listBaseUrl + '/_vti_bin/';
	var query = &quot;&quot;;
	$.each(findInArr,function(i,fin){
		query += &quot;&lt;Eq&gt;&lt;FieldRef Name='&quot;+fin+&quot;' /&gt;&lt;Value Type='Text'&gt;&quot;+find+&quot;&lt;/Value&gt;&lt;/Eq&gt;&quot;;
		if(i&gt;0)query = &quot;&lt;Or&gt;&quot; + query + &quot;&lt;/Or&gt;&quot;;
	});
	query = &quot;&lt;Where&gt;&quot; + query + &quot;&lt;/Where&gt;&quot;;
	var arrToReturn = [];
	res = queryItems(listGuid,query,['ID']);
	$.each(res.items,function(i,item){
		arrToReturn.push(item.ID);
	});
	return arrToReturn;
}

function filterCalendarView(arrOfIDs){
	$(&quot;.ms-cal-gempty a[href*='DispForm.aspx?ID=']&quot;).each(function(){
		var currID = $(this).attr('href').match(/ID=(d+)/);
		if($.inArray(currID[1],arrOfIDs)==-1){
			// remove
			var thisParentTd = $(this).parents('table:first').parents('td:first');
			var colspan = thisParentTd.attr('colspan');
			if(colspan&gt;1){		
				for(i=1;i&lt;colspan;i++){				
					thisParentTd.after(&quot;&lt;td class='ms-cal-workitem'&gt;&amp;nbsp;&lt;/td&gt;&quot;);
				}
				thisParentTd.replaceWith(&quot;&lt;td class='ms-cal-workitem'&gt;&amp;nbsp;&lt;/td&gt;&quot;);
			}else{
				thisParentTd.html('&amp;nbsp;');			
			}		
		}
	});
// Show calendar view after it has been filtered
$(&quot;.ms-cal-gempty&quot;).show();
}

function getUserInfo(UserId){
wsBaseUrl = userListBaseUrl + '/_vti_bin/';
var uiObj = {};

if(typeof(UserId)==&quot;undefined&quot; || UserId=='')UserId = _spUserId;

var arrOfFields = ['ID', 'Name', 'Title', 'EMail', 'Department', 'JobTitle', 'Notes', 'Picture',
'IsSiteAdmin', 'Created', 'Author', 'Modified', 'Editor', 'SipAddress', 'Deleted'];

var item = getItemById(userListGuid,UserId,arrOfFields);
    if(item != null){
	    for(i=0;i&lt;arrOfFields.length;i++){
	    	if(item[arrOfFields[i]]!=null){
	    		uiObj[arrOfFields[i]] = item[arrOfFields[i]];
	    	}else{
	    		uiObj[arrOfFields[i]] = '';
	    	}
	    }
       	return uiObj;
    }else{
        for(i=0;i&lt;arrOfFields.length;i++){
    		uiObj[arrOfFields[i]] = &quot;User with id &quot; + UserId + &quot; not found.&quot;;
    	}
		return uiObj;
	}
}	
&lt;/script&gt;

Modify the parameters:

  • listGuid: The list name or list Guid of the list to filter.
  • listBaseUrl: The base URL of the list to filter.
  • userListGuid: The list Guid of the user list (People and Groups).
  • userListBaseUrl: The user list base URL – Most likely an empty string “”. If the site resides on a manage path this must be reflected.
  • arrOfFieldInternalNames: Array of the FieldInternalNames to search for a match on the search string-

The jQuery-library is found here. The sourcecode refers to jquery-1.3.2.min.js. If you use another version, please update the reference in the code.

The scripts “interaction.js” and “stringBuffer.js” is created by Erucy and published on CodePlex.

Read here how to add a CEWP to NewForm or EditForm, and how to get the guid for a list.

I do not think this is a “production environment solution” at this stage, but please test it and post back any comments or suggestions and i will try to adapt the script.

Regards
Alexander

Pull e-mail from people picker and write to a separate textfield

18.09.2011 I have posted a new solution to this “problem”. I recommend you use the new one. You find it here


I got this request from Indra:

Hi Alex,

This is really great blog!! awesome work and i am big fan of this site, i check everyday and look at the things and learn , but i need something that i cannot find any where. Let me explain what i need..

I have a list with a people picker and a field called email address, i want to get the email address populated automatically depending the person on people picker ( single user). I know that i need to get user information from profile, but i am not a programmer and there i need your help.

I know you are really busy but please spotlight when you have time.

Thanks in Advance.

This code fills the e-mail address when the item is saved. It pulls the email address from a “resolved” user in a people picker, and writes it to a separate text field.

As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
IMG

The jQuery-library is found here. The pictures and the sourcecode refers to jquery-1.4.min. If you use another version, please update the reference in the code.

The scripts “interaction.js” and “stringBuffer.js” is created by Erucy and published on CodePlex.

Read here how to add a CEWP to NewForm or EditForm, and how to get the guid for a list.

Add this code to a CEWP below the NewForm or EditForm:

&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.4.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/interaction.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/stringBuffer.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
fields = init_fields();

userListGuid = '570D772F-0EAB-45A8-8C54-9CCD4EC6A0AF';
userListBaseUrl = '';
myPeoplePickerFin = 'MyPeoplePicker';
myTextFieldFin = 'MyTextField';

function PreSaveAction(){
	var myPeoplePicker = $(fields[myPeoplePickerFin]).find('.ms-formbody').find(&quot;div[id='divEntityData']&quot;);
	if(myPeoplePicker.length&gt;0){
		var isResolved = (myPeoplePicker.attr('isresolved').toLowerCase()=='true')?true:false;
		if(isResolved){	
			var login = myPeoplePicker.attr('description');	
			var uiObj = getUserInfoFromLogin(login);
			$(fields[myTextFieldFin]).find('input').val(uiObj.EMail);	
		}
	}
	return true;
}

function getUserInfoFromLogin(UserLogin){ //
wsBaseUrl = userListBaseUrl + '/_vti_bin/'; 
var retObj = {};
var arrOfFields = ['ID','Name','Title','EMail','Department','JobTitle','Notes','Picture','IsSiteAdmin',
				   'Created','Author','Modified','Editor','SipAddress','Deleted'];
				   
var query = &quot;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Name' /&gt;&lt;Value Type='Text'&gt;&quot; + UserLogin + &quot;&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&quot;;
var res = queryItems(userListGuid,query,arrOfFields,1); 
    if(res.count&gt;0){ 
	    for(i=0;i&lt;arrOfFields.length;i++){
	    	retObj[arrOfFields[i]] = res.items[0][arrOfFields[i]];    
	    }
       	return retObj; 	
    }else{
        for(i=0;i&lt;arrOfFields.length;i++){
    		retObj[arrOfFields[i]] = &quot;User with id &quot; + UserLogin + &quot; not found.&quot;;    
    	}
		return retObj; 
	}
}

function init_fields(){
var res = {};
$(&quot;td.ms-formbody&quot;).each(function(){
if($(this).html().indexOf('FieldInternalName=&quot;')&lt;0) return;
var start = $(this).html().indexOf('FieldInternalName=&quot;')+19;
var stopp = $(this).html().indexOf('FieldType=&quot;')-7;
var nm = $(this).html().substring(start,stopp);
res[nm] = this.parentNode;
});
return res;
}
&lt;/script&gt;

You must change these four parameters in the script:

  • userListGuid: The listGuid of the user list
  • userListBaseUrl: The base URL for the userList. Most likely an empty string “”, but If the site resides on a managed path, this must be reflected.
  • myPeoplePickerFin: FieldInternalName for the people picker
  • myTextFieldFin: FieldInternalName for the single line text field to hold the email address

Ask if anything is unclear.

Regards
Alexander

Filter Radio Buttons or Checkboxes based on selection in another field

Change log:

06.10.2010 Fixed a bug with unchecking hidden options when using a multi choice checkbox type column as “consumer” column (line 84 in the code). Thanks to Mike for finding the bug.

31.08.2010 Modified the code to hide the “consumer field” entirely if no items is visible.

16.07.2010 Updated the code to support checkboxes (allow multiple selections) in both “trigger” and “consumer” columns. I have also changed the logic from using the index of the option to use the actual text value.

15.03.2010 small update to the code to handle blank “triggervalue”. Thanks to Larry.


I got this request from Elstone:

Hello

I have two choice fields, 1 drop down and another is multiple radio buttons (6 values/radio button). This I want to implement on newform/editform

In dropdown I have 3 values i.e. Yes/No/Not Sure (selected by default).

I want to show/hide some of the radio buttons out of 6 radio buttons depending on condiion.

Let say
if user select “Yes”, then show radiobutton1 and radiobutton 3
If user select “No” , then show radiobutton2 and radiobutton 5
If user select “Not Sure” then show all the radio buttons

How can I do this?


IMG

IMG

This script will work for single value <select>, Radio Buttons and Checkboxes. The script will uncheck all hidden options, so if you flip the selection from “Yes” to “No” any selections made under “Yes” will be cleared.

As always we start like this:
Create a document library to hold your scripts (or a folder on the root created in SharePoint Designer). In this example i have made a document library with a relative URL of “/test/English/Javascript” (a sub site named “test” with a sub site named “English” with a document library named “Javascript”):
IMG
Note: picture refers to jquery-1.3.2.min.js, but code uses jquery-1.4.2.min.js.

The jQuery-library is found here. The sourcecode refers to jquery-1.4.2.min. If you download another version, be sure to update the script reference in the sourcecode.

Add this code to a CEWP below the list form in NewForm and EditForm:

&lt;script type=&quot;text/javascript&quot; src=&quot;../../Javascript/jquery-1.4.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Make object of all TR
fields = init_fields_v2();

// Call function with FieldInternalName of triggerfield and targetfield
init_hideRadiobuttons('MyTriggerColumn','MyRadioButton');

function init_hideRadiobuttons(triggerColumnFIN,radioButtonFIN){
var type = 'single';
if($(fields[triggerColumnFIN]).find('input').length&gt;0)type = 'multi';
	var thisVal = [];
	switch(type){
	case 'single':
		// Onload
		thisVal.push($(fields[triggerColumnFIN]).find('option:selected').text());
		hideRadiobuttons(radioButtonFIN,thisVal);
		// Onchange
		$(fields[triggerColumnFIN]).find('select').change(function(){
		thisVal = [];
			thisVal.push($(this).find('option:selected').text());
			hideRadiobuttons(radioButtonFIN,thisVal);
		});
	break;
	case 'multi':	
		// Onload
		$(fields[triggerColumnFIN]).find('input').each(function(){
			if($(this).attr('checked')){
				thisVal.push($(this).next().text());
			}
		});
		hideRadiobuttons(radioButtonFIN,thisVal);			

		// Onclick
		$(fields[triggerColumnFIN]).find('input').click(function(){
		thisVal = [];
			$(fields[triggerColumnFIN]).find('input').each(function(){
				if($(this).attr('checked')){
					thisVal.push($(this).next().text());
				}
			});
			hideRadiobuttons(radioButtonFIN,thisVal);			
		});
		break;
	}
}

function hideRadiobuttons(FieldInternalName,arrOfValues){
var showArr = [];
	$.each(arrOfValues,function(i,val){
		switch(val){
			case 'Yes':
				showArr.push('Selected Yes - option 1',
							 'Selected Yes - option 2',
							 'Selected Yes - option 3');
			break;
			case 'No':
				showArr.push('Selected No - option 1',
							 'Selected No - option 2',
							 'Selected No - option 3');
			break;
			case 'Not Sure':
				showArr.push('Selected Yes - option 1',
							 'Selected Yes - option 2',
							 'Selected Yes - option 3',
							 'Selected No - option 1',
							 'Selected No - option 2',
							 'Selected No - option 3');
			break
		}
	});
	if(showArr.length==0){
		// Hide row
		$(fields[FieldInternalName]).hide();
	}else{
		// Unhide row
		$(fields[FieldInternalName]).show();
		// Show options
		$(fields[FieldInternalName]).find('label').each(function(){
			var thisVal = $(this).text();
			if($.inArray(thisVal,showArr)&gt;-1){
				$(this).parents('tr:first').show();
			}else{
				$(this).prev().attr('checked',false)
				$(this).parents('tr:first').hide();			
			}
		});
	}
}

/*
  LastMod: 07.05.2010
*/
function init_fields_v2(){
	var res = {};
	$(&quot;td.ms-formbody&quot;).each(function(){
	var myMatch = $(this).html().match(/FieldName=&quot;(.+)&quot;s+FieldInternalName=&quot;(.+)&quot;s+FieldType=&quot;(.+)&quot;s+/);	
		if(myMatch!=null){
			// Display name
			var disp = myMatch[1];
			// FieldInternalName
			var fin = myMatch[2];
			// FieldType
			var type = myMatch[3];
			if(type=='SPFieldNote'){
				if($(this).find('script').length&gt;0){
					type=type+&quot;_HTML&quot;;
				}
			}
			if(type=='SPFieldLookup'){
				if($(this).find('input').length&gt;0){
					type=type+&quot;_Input&quot;;
				}
			}
			// Build object
			res[fin] = this.parentNode;
			res[fin].FieldDispName = disp;
			res[fin].FieldType = type;
		}		
	});
	return res;
}
&lt;/script&gt;

You must update the “cases” in the function “hideRadiobuttons” to match your setup.

Read here how to add a CEWP to the NewForm, DispForm or EditForm, and how to find the FieldInternalName of your columns.

Regards
Alexander

Add character or word count to SharePoint multi line plain text field and restrict input length

13.03.2011 Updated the code to handle pasting into the field by adding “blur” eventhandler. Referred jQuery from Google.


14.03.2010 Updated to count down from limit to 0 and color code the counter. Also merged the “Count characters” and the “Count words” functions to one. See new code and explanation below.

I got this request from Larry:

new request for you. Character/word counter for multiple line field to display below the field. Not general for all multiple lines, but setup in a way that can set fieldinternalnames in am arr. also can we add a character limit, so user can not enterany more text.

I have several character counters. cant get it on the form. I am also looking into adding it on the create field page. calculated fields can only accept about 1000 characters. would like a way to display the count on that page.

I cannot help with the “create new column page”, as it is a server side file, shared between all site collections running on this server.


IMG

Add a CEWP below your NewForm and EditForm and add this code:
Get the code here

Parameters explained:

  • FieldInternalName: FieldInternalName of the multi line plain text field.
  • countWords: true to count words, false to count characters.
  • limit: 0 for no limit and count up, a value bigger then 0 to set a limit and to count down.
  • colorCodeCounter: true to add orange/red coding when limit is approaching.
  • counterPrefix: The text to show before the counter.

Read here how to add a CEWP to the NewForm or EditForm and how to find the FieldInternalName of your columns.

Ask if anything is unclear
Alexander

Show active list filter above list view

I got this request:

Hi Alexander:
Another “is it possible?” question…

Is it possible to have a specific column’s filter choice appear in a CEWP that I would place above a list view?

Example: Filter the page by [Customer]
CWEP: would contain text + [Customer]

Thanks-

Charlie Epes


To pull the list filter from the URL and display it above the web part, put this code in a CEWP below the webpart (change the reference to jQuery if necessary):

&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
/* This code must be placed below the webpart it shall reflect */
// Get all querystring parameters
var queryString = getQueryParameters();

// Get all DisplayNames for the columnFilter
objFinDisp = {};
$(&quot;.ms-viewheadertr th&quot;).each(function(){
	objFinDisp[$(this).find('table:first').attr('name')] = $(this).find('table:first').attr('displayname');
});

// Loop trough and extract all querystring parameters that has &quot;Filter&quot; in it
myFilterStr = '';
$.each(queryString,function(param,val){
	if(param.indexOf('FilterField')==0 || param.indexOf('FilterValue')==0){
		// Switch the FieldInternalName for the DisplayName
		if(objFinDisp[val]!=undefined)val=objFinDisp[val];
		// Write the filter
		if(param.indexOf('FilterField')==0){
			myFilterStr += decodeURI(val)+&quot; = &quot;;
		}else{
			myFilterStr += decodeURI(val)+&quot;&lt;br&gt;&quot;;
		}
	}
});

// Put filter string in the top of the page
$(&quot;.ms-bodyareaframe&quot;).prepend(&quot;&lt;div&gt;&quot;+myFilterStr+&quot;&lt;/div&gt;&quot;);

// Function to separate each url search string parameters
function getQueryParameters(){
qObj = {};
var urlSearch = window.location.search;
	if(urlSearch.length&gt;0){
		var qpart = urlSearch.substring(1).split('&amp;');
		$.each(qpart,function(i,item){
			var splitAgain = item.split('=');
			qObj[splitAgain[0]] = splitAgain[1];
		});
	}
return qObj;
}
&lt;/script&gt;

Alexander

SharePoint form – Accordion in Tabs

This is a draft/example to keep Steve busy over the weekend 🙂 (see his request here).

To get anything out of this code, you have to read the following articles: Tabs in SharePoint form and Accordion in SharePoint form


Here is the code:

&lt;!-- Date field text size --&gt;
&lt;style type=&quot;text/css&quot;&gt;
.ms-dtinput,.ms-dttimeinput{
	font-size:0.7em;
}
&lt;/style&gt;
&lt;DIV id=&quot;tabs&quot;&gt;
	&lt;UL style=&quot;font-size:12px&quot;&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-1&quot;&gt;Tab 1&lt;/A&gt;&lt;/LI&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-2&quot;&gt;Tab 2&lt;/A&gt;&lt;/LI&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-3&quot;&gt;Tab 3&lt;/A&gt;&lt;/LI&gt;
	&lt;/UL&gt;

	&lt;div id=&quot;tabs-1&quot;&gt;	
		&lt;div id=&quot;accordion-1&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-0&quot;&gt;Tab 1 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-0&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-1&quot;&gt;Tab 1 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-1&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-2&quot;&gt;Tab 1 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-2&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;	
	&lt;/div&gt;
	&lt;div id=&quot;tabs-2&quot;&gt;
		&lt;div id=&quot;accordion-2&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-3&quot;&gt;Tab 2 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-3&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-4&quot;&gt;Tab 2 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-4&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-5&quot;&gt;Tab 2 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-5&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-3&quot;&gt;
		&lt;div id=&quot;accordion-3&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-6&quot;&gt;Tab 3 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-6&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-7&quot;&gt;Tab 3 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-7&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-8&quot;&gt;Tab 3 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-8&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/DIV&gt;

&lt;link type=&quot;text/css&quot; href=&quot;/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Array of all fields - format: accordionID|FieldInternalName
arrTabAccordion = ['0|Title','0|Dummyfield1','0|Dummyfield2',
			'1|Dummyfield3','1|Dummyfield4','1|Dummyfield5',
			'2|Dummyfield6','2|Dummyfield7','2|Dummyfield8',
			'3|Dummyfield9','3|Dummyfield10','3|Dummyfield11',
			'4|Dummyfield12','4|Dummyfield13','4|Dummyfield14',
			'5|Dummyfield15','5|Dummyfield16','5|Dummyfield17',
			'6|Dummyfield18','6|Dummyfield19','6|Dummyfield20',
			'7|Dummyfield21','7|Dummyfield22','7|Dummyfield23',
			'8|Dummyfield24','8|Dummyfield25','8|Dummyfield26'];

// Initiate all the fields
fields = init_fields();

// Add the &quot;tabs&quot; to the formtable
$(&quot;#tabs&quot;).insertAfter('.ms-formtable').tabs();
// Add accordion
$(&quot;#accordion-1&quot;).accordion({autoHeight: false,animated: false});
$(&quot;#accordion-2&quot;).accordion({autoHeight: false,animated: false});
$(&quot;#accordion-3&quot;).accordion({autoHeight: false,animated: false});

// Loop trough all fields and move them to the right accordion section
$.each(arrTabAccordion,function(idx,item){
	var split = item.split('|');
	var accID = split[0];
	var fieldName = split[1];
	if(fields[fieldName]!=undefined){
		currField = $(fields[fieldName]);
		currField.appendTo('#accTable-'+accID);
	}
});

// Fix IE8 issue with zoom
$(&quot;.ui-accordion-content&quot;).css({'zoom':1,'padding':'0px'});

// function - to make &quot;object&quot; of all tr's in the form
function init_fields(){
  var res = {};
  $(&quot;td.ms-formbody&quot;).each(function(){
	  if($(this).html().indexOf('FieldInternalName=&quot;')&lt;0) return;
	  var start = $(this).html().indexOf('FieldInternalName=&quot;')+19;
	  var stopp = $(this).html().indexOf('FieldType=&quot;')-7;
	  var nm = $(this).html().substring(start,stopp);
	  res[nm] = this.parentNode;
  });
  return res;
}
&lt;/script&gt;

This is the same code, but added two fields to tab-2, outside the accordion:

&lt;!-- Date field text size --&gt;
&lt;style type=&quot;text/css&quot;&gt;
.ms-dtinput,.ms-dttimeinput{
	font-size:0.7em;
}
&lt;/style&gt;
&lt;DIV id=&quot;tabs&quot;&gt;
	&lt;UL style=&quot;font-size:12px&quot;&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-1&quot;&gt;Tab 1&lt;/A&gt;&lt;/LI&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-2&quot;&gt;Tab 2&lt;/A&gt;&lt;/LI&gt;
		&lt;LI&gt;&lt;A href=&quot;#tabs-3&quot;&gt;Tab 3&lt;/A&gt;&lt;/LI&gt;
	&lt;/UL&gt;

	&lt;div id=&quot;tabs-1&quot;&gt;	
		&lt;div id=&quot;accordion-1&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-0&quot;&gt;Tab 1 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-0&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-1&quot;&gt;Tab 1 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-1&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-2&quot;&gt;Tab 1 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-2&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;	
	&lt;/div&gt;
	&lt;div id=&quot;tabs-2&quot;&gt;
	&lt;table cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; id=&quot;tabs-2-table&quot;&gt;&lt;/table&gt;
		&lt;div id=&quot;accordion-2&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-3&quot;&gt;Tab 2 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-3&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-4&quot;&gt;Tab 2 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-4&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-5&quot;&gt;Tab 2 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-5&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;
	&lt;/div&gt;
	&lt;div id=&quot;tabs-3&quot;&gt;
		&lt;div id=&quot;accordion-3&quot;&gt;	
			&lt;H3&gt;&lt;A href=&quot;#accordion-6&quot;&gt;Tab 3 Accordion 1&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-6&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-7&quot;&gt;Tab 3 Accordion 2&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-7&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;
			&lt;H3&gt;&lt;A href=&quot;#accordion-8&quot;&gt;Tab 3 Accordion 3&lt;/A&gt;&lt;/H3&gt;
			&lt;div&gt;&lt;table width=&quot;100%&quot; id=&quot;accTable-8&quot;&gt;&lt;/table&gt;&amp;nbsp;&lt;/div&gt;	
		&lt;/div&gt;
	&lt;/div&gt;
&lt;/DIV&gt;

&lt;link type=&quot;text/css&quot; href=&quot;/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.css&quot; rel=&quot;stylesheet&quot; /&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jQueryUI/jquery-ui-1.7.2.custom.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
// Array of all fields - format: accordionID|FieldInternalName
arrTabAccordion = ['0|Title','0|Dummyfield1','0|Dummyfield2',
			'1|Dummyfield3','1|Dummyfield4','1|Dummyfield5',
			'2|Dummyfield6','2|Dummyfield7','2|Dummyfield8',
			'3|Dummyfield9','3|Dummyfield10','3|Dummyfield11',
			'4|Dummyfield12','4|Dummyfield13','4|Dummyfield14',
			'5|Dummyfield15','5|Dummyfield16','5|Dummyfield17',
			'6|Dummyfield18','6|Dummyfield19','6|Dummyfield20',
			'7|Dummyfield21','7|Dummyfield22','7|Dummyfield23',
			'8|Dummyfield24','8|Dummyfield25','8|Dummyfield26'];

arrTab = ['1|FieldInTab1','1|FieldInTab2'];

// Initiate all the fields
fields = init_fields();

// Add the &quot;tabs&quot; to the formtable
$(&quot;#tabs&quot;).insertAfter('.ms-formtable').tabs();
// Add accordion
$(&quot;#accordion-1&quot;).accordion({autoHeight: false,animated: false,collapsible: true,active: false});
$(&quot;#accordion-2&quot;).accordion({autoHeight: false,animated: false,collapsible: true,active: false});
$(&quot;#accordion-3&quot;).accordion({autoHeight: false,animated: false,collapsible: true,active: false});

// Loop trough all fields and move them to the right accordion section
$.each(arrTabAccordion,function(idx,item){
	var split = item.split('|');
	var accID = split[0];
	var fieldName = split[1];
	if(fields[fieldName]!=undefined){
		currField = $(fields[fieldName]);
		currField.appendTo('#accTable-'+accID);
	}
});

// Loop trough all fields and move them to the right tab
$.each(arrTab,function(idx,item){
	var split = item.split('|');
	var tabID = split[0];
	var fieldName = split[1];
	if(fields[fieldName]!=undefined){
		currField = $(fields[fieldName]);
		currField.appendTo('#tabs-2-table');		
	}
});

// Fix IE8 issue with zoom
$(&quot;.ui-accordion-content&quot;).css({'zoom':1,'padding':'0px'});

// function - to make &quot;object&quot; of all tr's in the form
function init_fields(){
  var res = {};
  $(&quot;td.ms-formbody&quot;).each(function(){
	  if($(this).html().indexOf('FieldInternalName=&quot;')&lt;0) return;
	  var start = $(this).html().indexOf('FieldInternalName=&quot;')+19;
	  var stopp = $(this).html().indexOf('FieldType=&quot;')-7;
	  var nm = $(this).html().substring(start,stopp);
	  res[nm] = this.parentNode;
  });
  return res;
}
&lt;/script&gt;

This example is setup in a custom list with 26 single line text fields (Dummyfield1-26).

I have stripped off everything related to selecting the correct tab or accordion on form validation.

I may update this code later.

Regards
Alexander

Validate text field input against value in another list

I got this request from Sonaly:

I am using MOSS.

I have two lists Machines and TRansactions.

I have 3 following textboxes in newform.aspx/editform.aspx of Transactions List.

EnqNo – Plain Text box – Required field
Date – Datetime field – Required field
MachineID – Plain Text box – Required field

Here I want to validate Machine ID from Machines List (MachineId column) before save record into transaction list

Let me know if you need more information,


Alexander Says:
Take a look at this script: Convert Singleline textfield to filtered lookup dropdown and see if this could fill your need.

The script will convert your “MachineID” to a lookup from the list “Machines”.

Alexander


Sonaly Says:
Alexandar

I dont want to use lookup field as I have 1000+ item and it is not user friendly , that is why I am thinking of using Textbox coumn and validation.

Any other advise


This example has a two list setup with only the “Title” field present in each list. You will have to edit the FieldInternalName to match your fields.

Add this code to a CEWP below the form in NewForm and EditForm in the list the user will input the value in:

&lt;style type=&quot;text/css&quot;&gt;
.customError{
	background-color:#FF6A6A;
}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/interaction.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;/test/English/Javascript/stringBuffer.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
fields = init_fields();

// Attach a function to the blur event of the &quot;Title&quot; field
$(fields['Title']).find('input').blur(function(){
	var thisVal = $(this).val();
	validateTextAgainstList($(this));
});

function validateTextAgainstList(obj){
str = obj.val();
wsBaseUrl = L_Menu_BaseUrl + '/_vti_bin/';
// Edit the &quot;Title&quot; to match your FieldInternalName
var query = &quot;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name='Title' /&gt;&lt;Value Type='Text'&gt;&quot;+str+&quot;&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&quot;;
// Edit the list GUID to match your list - or use the list's displayName
	var itemCount = queryItemCount('D54206E8-5E98-4DCD-9D3D-39C321FD0792',query);
	if(itemCount==0){		
		$(&quot;input[id$='SaveItem']&quot;).attr('disabled',true);
		obj.addClass('customError');
		alert(&quot;Sorry mate, this value is not correct.&quot;);
	}else{
		// OK
		$(&quot;input[id$='SaveItem']&quot;).attr('disabled',false);
		obj.removeClass('customError');
	}
}

function init_fields(){
var res = {};
$(&quot;td.ms-formbody&quot;).each(function(){
if($(this).html().indexOf('FieldInternalName=&quot;')&lt;0) return; 
var start = $(this).html().indexOf('FieldInternalName=&quot;')+19;
var stopp = $(this).html().indexOf('FieldType=&quot;')-7; 
var nm = $(this).html().substring(start,stopp);
res[nm] = this.parentNode;
});
return res;
}
&lt;/script&gt;

You will have to edit the FieldRef Name=’Title’ to match your fields FieldInternalName, and the list GUID (D54206E8-5E98-4DCD-9D3D-39C321FD079) to match your list – or use the list’s displayName.

The jQuery-library is found here. The sourcecode refers to jquery-1.3.2.min. If you download another version, be sure to update the script reference in the sourcecode.

The scripts “interaction.js” and “stringBuffer.js” is created by Erucy and published on CodePlex.

Read here how to add a CEWP to the NewForm, DispForm or EditForm, how to find the list Guid of your list, and how to find the FieldInternalName of your columns.

Regards
Alexander