2009/02/14

Get SelectedValue from sharepoint lookup Field


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

<SharePoint:FieldDescription runat="server" id="ff30description{$Pos}" FieldName="_x0627__x0644__x0628__x0646__x06" ControlMode="New"/>

To get the selectedvalue from sharepoint lookup field you follow these steps.

first you need to assign event onchange to this field.


<script type="text/javascript" language="javascript">
//Select the method that will run at the sharepoint page body load

_spBodyOnLoadFunctionNames.push('setEvent');

//set event function
function setEvent()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');

//eventName and method that will call
selectBank.setAttribute('onchange',checkBank);


}

//function will call when event is fired
function checkBank()
{
var selectBank= document.getElementById('ctl00_m_g_8f64049a_17a6_4a6d_89a3_c227374a7f7a_ff30_1_ctl00_Lookup');
var selectedValue=selectBank.options[selectBank.selectedIndex].value;
alert(selectedValue)

}

</script>


No comments: