0

I have a radio Item SharePoint and radio button in HTML code. what I need It's: when I check on radio buton,the radio Item will be checked : If I check "yes", the "yes" of SharePoint item will be cheked, and the reverse. So,how can I set the value to the SharePoint item without c# coding?

this is the html code:

<td width="190px" valign="top" class="ms-formlabel">
    <H3 class="ms-standardheader">                              
        <nobr>Lien avec courrier antérieur* </nobr>                     
    </H3>                       
</td>       
<td>
    <input type= "radio" id ="b" name="radstate"></input>yes
    <input type= "radio" id ="a" name="radstate" checked="checked"></input>No<br/>
</td>

this is the xsl code:

<td width="190px" valign="top" class="ms-formlabel">
    <H3 class="ms-standardheader">
        <nobr>Lien avec courrier antérieur</nobr>
    </H3>
</td>
<td width="400px" valign="top" class="ms-formbody">
    <SharePoint:FormField runat="server" id="ff11{$Pos}" ControlMode="New" FieldName="Lien_x0020_avec_x0020_courrier_x" __designer:bind="{ddwrt:DataBind('i',concat('ff11',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Lien_x0020_avec_x0020_courrier_x')}"/>
    <SharePoint:FieldDescription runat="server" id="ff11description{$Pos}" FieldName="Lien_x0020_avec_x0020_courrier_x" ControlMode="New"/>
</td>

1 Answer 1

1

You can do this using jQuery or JavaScript. Use following code block to capture the checked event

jQuery(document).ready(function()
{
    jQuery("input[name='radstate']").change(radioValueChanged);
})

function radioValueChanged()
{
    radioId = jQuery(this).attr('id');

    if(jQuery(this).is(":checked") && radioId == "a")
    {
        UpdateListValue(true);
    }
    else if(jQuery(this).is(":checked") && radioId == "b")
    {
        UpdateListValue(false);
    }
} 

Now we need to use SharePoint JavaScript Object Model to save information back to the list

var siteUrl = '/sites/MySiteCollection';

function updateListItem() {
var clientContext = new SP.ClientContext(siteUrl);
var oList = clientContext.get_web().get_lists().getByTitle('LISTNAME');

this.oListItem = oList.getItemById(ITEMID); //Number

oListItem.set_item('FieldInternalName', NEWVALUE);
oListItem.update();

clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

function onQuerySucceeded() {
    alert('Item updated!');
}

function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

More on JSOM http://msdn.microsoft.com/en-us/library/office/hh185011(v=office.14).aspx

2
  • With javascript Object Model, I must use visual studio.is there another way to do it without visual studio, may be with sharepoint designer ? Thanks
    – Imen Turki
    Commented Oct 17, 2014 at 8:47
  • Yes. You can use any text editor and then copy the code into a Content Editor webpart. Commented Oct 17, 2014 at 14:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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