I'm sorry if this is really obvious, however, I haven't found ANYTHING that explains it... using a SharePoint:FormField. I've found countless resources on how to do the following in HTML, but when I've tried to apply it to SharePoint jQuery breaks!!
So I have a SharePoint:FormField like the following
<tr>
<td width="190px" valign="top" class="ms-formlabel">
<H3 class="ms-standardheader">
<nobr>Request Type<span class="ms-formvalidation"> *</span>
</nobr>
</H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
<SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="New" FieldName="requestType" __designer:bind="{ddwrt:DataBind('i',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@requestType')}"/>
<SharePoint:FieldDescription runat="server" id="ff3description{$Pos}" FieldName="requestType" ControlMode="New"/>
</td>
</tr>
And I'm just trying to get the value of SOMETHING, ANYTHING to appear in an alert, but it's giving me an undefined alert
<script type="text/javascript">
$(document).ready(function(){
var myVar = $("SharePoint:FormField[FieldName]").val()
alert(myVar);
// result "undefined"
});
</script>
Please help. Many Thanks!
Your problem is that javascript is run on the client side. If you have a look at the source of your page in your web browser (view source), you will see that you will not find
SharePoint:FormField
anywhere in it. This is becauseSharePoint:FormField
is not an HTML tag at all. This field will be replaced by a number of actual html tags.SharePoint:FormField
is processed and replaced on the server-side.You will need to have a look at the tags which are generated and then access those.