admin管理员组

文章数量:1292122

I want to copy the content of a sharepoint form field to a variable using Javascript.

Eg. I have a field named "Language" in my sharepoint edit form. Now I just want to get the value of that field to a varaible x.

Please help.

BR

I want to copy the content of a sharepoint form field to a variable using Javascript.

Eg. I have a field named "Language" in my sharepoint edit form. Now I just want to get the value of that field to a varaible x.

Please help.

BR

Share Improve this question asked Dec 19, 2011 at 9:51 SijoSijo 331 gold badge1 silver badge7 bronze badges 2
  • I want to validate that field value to check if there is a blank space. But dont know how to get the field value to a variable. Is there any javascript function to get it? like getElementByID..or something like that? – Sijo Commented Dec 19, 2011 at 10:02
  • Is this SharePoint 2007 or 2010? Are you using jQuery? – Athens Holloway Commented Dec 19, 2011 at 16:23
Add a ment  | 

3 Answers 3

Reset to default 2

It depends on the type (e.g. user, lookup, multilookup, text, note, etc.) of field. I am using jQuery in my custom list forms and the name of the field for any given content type will be added to the id of the corresponding html control with the text 'Field' appended to it. However, like any typical asp control, the id of the html form control rendered to the client will reflect its control hierarchy so you have to account for that when searching for a field. anyhow, the following works for me if i need to reference fields in my custom forms. ** notice the +Field which implies that the name of the field is concatenated with 'Field'

var $titleField = $('input[id*=TitleField]');
var $lookupField = $('select[id*=Name_Of_Field+Field]')
var $multiLookUpCandidate = $('select[id*=Name_Of_Field+Field][id*=SelectCandidate]')
var $multiLookUpResult = $('select[id*=Name_Of_Field+Field][id*=SelectResult]')
var $note = $('textarea[id*=Name_Of_Field+Field]');

You can pick up on the trend by viewing source and seaching for your contenttype/sitecolumn field name. You will find it in an html form control id. use that information to learn how to reference other field types.

Without posting your code its very difficult to understand what you want to do.... to get a value from a form you can do the following :

HTML

<form id="myform">
  <input id="myinput" type="text" value="something" />
</form>

JavaScript:

var myinputval = document.getElementById("myinput").value;

myinputval would be "something" in this example

Demo : http://jsfiddle/Qk6FZ/

This might help:

http://depressedpress./2012/09/24/obtaining-a-javascript-reference-to-a-sharepoint-field/

Using that function you'd get the reference using something like:

var LanguageFld = getFieldRef("Language");

Once you have the refernece it's easy to get the value:

var CurValue = LanguageFld.value;

Hope this helps!

本文标签: Javascript to get sharepoint form field value to a variableStack Overflow