Logo 
Search:

Sharepoint Forum

Ask Question   UnAnswered
Home » Forum » Sharepoint       RSS Feeds

Refer to a SharePoint document library field using JavaScript

  Asked By: Cara    Date: Dec 17    Category: Sharepoint    Views: 2931

The strict answer to your question is to use JavaScript similar to this:

var emailAddressField =
document.getElementsByName(frm.stFieldPrefix + "Email")[0];

This gets the first element (zeroth and probably the only element) in an
array with a tag name that ends in the field's internal name (or URL
name): "Email". I've just hijacked the prefix, frm.stFieldPrefix,
defined by SharePoint and used in their own script functions. Note that
the title property of the emailAddressField object will be the display
name of the field.


More broadly, the JavaScript below shows an example of how to capture a
JavaScript function (in this case SubmitForm) and override it with your
own implementation. In this example, I wanted the user to enter a valid
email address before saving an existing default Contact listitem (the
function name is different for a new Contact listitem).

You can implement this solution in one of two ways:

1. Navigate to an existing Contact list or create a new one.
Open a listitem for editing (you may have to create a contact
listitem).
Add a generic CEWP to the bottom of the EditForm.aspx page. (see
http://tinyurl.com/lzxhz" target="_blank" rel="nofollow">http://tinyurl.com/lzxhz for help)
Modify Shared Web Part and click the Source Editor... button.
Drop in my JavaScript and click the Save button.
Note: The OK, Cancel, and Apply buttons on the tool pane will not
work because the form is connected with the toolbar.

2. Add my CEWP (attached) to the Web Part Gallery in the top-level Web
of your site collection.
Navigate to an existing Contact list or create a new one.
Open a listitem for editing (you may have to create a contact
listitem).
Drag and drop the Field Validation Web Part the bottom of the page.
(see http://tinyurl.com/lzxhz" target="_blank" rel="nofollow">http://tinyurl.com/lzxhz for help)

Now, whenever any user attempts to edit an existing contact, if they
enter or alter the email address, it will be validated using the regular
expression before they are allowed to save the record.

Share: 

 

No Answers Found. Be the First, To Post Answer.

 




Tagged: