Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I've got a List in SP2010 and am trying to update a value with a little javascript and I'm not sure what I ought to be doing.

I've set the default List Form WebPart to false, and added a custom list form.

I've got a FormField in my NewForm.aspx file that looks like this in Sharepoint Designer:

<td width="400px" valign="top" class="ms-formbody">
                            <SharePoint:FormField runat="server" id="ff2{$Pos}" ControlMode="New" FieldName="Polygon" __designer:bind="{ddwrt:DataBind('i',concat('ff2',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Polygon')}"/>
                            <SharePoint:FieldDescription runat="server" id="ff2description{$Pos}" FieldName="Polygon" ControlMode="New"/>
                        </td>

But I'm not sure what the id of the object ought to be, I gave a simple try with:

$("#ff2{$Pos}").Value=res;

but that doesn't seem to be right.

I'm not finding it so easy to analyse the source that comes in my browser, it seems possible that the field gets an Id like:

ctl00$m$g_999175ee_0976_4d22_ad09_003284566eb9$ff2_1$ctl00$ctl00$TextField_spSave

which just seems crazy.

Am I going about this wrongly? Am I looking at this wrongly?

share|improve this question

1 Answer 1

up vote 2 down vote accepted

Basically, html field rendering element has attribute title equals to the field's title. It means that you can set value for text field (assuming it has name My Column and type text field):

$("input[title='My Column']").val("my val");

and this should be sufficient.

share|improve this answer
    
Really quite close here. This works for things like single lines and numbers, but not for the field I'm using which is a "Multiple lines of text" type. Does that make a difference? –  Dave Alger Mar 20 '12 at 12:35
1  
"Multiple lines of text" renders as textarea element (not input), so you need a little bit modify selector - $("textarea[title='My Column']").val("my val"); or you can even use more easy selector (but it also should be tested with different field types) - $("[title='My Column']").val("my val"); –  Kai Mar 20 '12 at 12:45
    
I had tried the textarea version without success and was starting to wonder. I checked the properties of the field and it was set as being able to handle Rich Text (which I don't need). So I set it to just plain text and now it works. Thanks! –  Dave Alger Mar 20 '12 at 13:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.