0

I want to set default URL for Publishing Link Column in my SharePoint New Item form using javascript.

Below Field's value should be set to http://a.com/ on form load.

<SharePoint:FormField runat="server" id="ff3{$Pos}" ControlMode="New" FieldName="Link" __designer:bind="{ddwrt:DataBind('i',concat('ff3',$Pos),'Value','ValueChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@Link')}" />
<SharePoint:FieldDescription runat="server"   id="ff2description1{$Pos}" FieldName="Link" ControlMode="New" />

Thanks

1

The following function could be used for specifying Publishing Hyperlink column on the client side:

function setPublisingHyperlinkValue(fieldInternalName,url,description)
{
    var fieldUrl = $('input[id ^=' + fieldInternalName +  '][id $=UrlFieldUrl]');
    var fieldDesc = $('input[id ^=' + fieldInternalName + '][id $=UrlFieldDescription]');
    fieldUrl.val(url);
    fieldDesc.val(description);
}

Example:

1.Open Form page (EditForm.aspx) in Edit mode

2.Add Content Editor web part

3.Insert the following code into web part Content in order to set default value (url: http://microsoft.com, desc: MSFT) for TargetUrl field:

<script type="text/javascript">
function setPublisingHyperlinkValue(fieldInternalName,url,description)
{
    var fieldUrl = $('input[id ^=' + fieldInternalName +  '][id $=UrlFieldUrl]');
    var fieldDesc = $('input[id ^=' + fieldInternalName + '][id $=UrlFieldDescription]');
    fieldUrl.val(url);
    fieldDesc.val(description);
}

$(function() {
   setPublisingHyperlinkValue('RedirectURL','http://www.microsoft.com','MSFT');
});
</script>​

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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