Search This Blog

Thursday 26 September 2013

radio button validation using jquery in sharepoint Designer form

<script  type="text/javascript">
   $(function() {
    var str = $('input[name*=ff200]').get(1).id;
    document.getElementById(str).setAttribute('checked','checked');
  })
</script>
Here we have a Radio button with Yes and No Options.

The XSLT of Radio button in SharePoint is

<SharePoint:FormField runat="server" id="ff200{$Pos}" ControlMode="Edit" FieldName="FeedbackCompleted" __designer:bind="{ddwrt:DataBind('u',concat('ff200',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@FeedbackCompleted')}"/>



$('input[name*=ff200]') - It searches the input element whose name contains ff200 which is the in ID of the SharePoint FormField.

var str = $('input[name*=ff200]').get(1).id; line finds the ID of the Element, As radio button has two or more options but in SharePoint it is FormField. So you want to find id of First Radio Button use get(0), Second Radio button use get(1) etc. 

No comments:

Post a Comment