Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Adding Javascript to Bizform field View modes: 
User avatar
Member
Member
tspring-allegra - 12/17/2010 12:46:34 PM
   
Adding Javascript to Bizform field
Hi

I was wondering if anyone knew how to add javascript to a field within a Bizform.

Particularly I want to add an OnChange function to a Drop-down list.

I'm editing code within a custom Bizform that i've cloned from the master Bizform webpart.

I've tried things like:
viewBiz.BasicForm.FieldControls["MyFieldName"].Attributes.Add("OnChange", "javascriptcode");
viewBiz.BasicForm.DataRow["MyFieldName"].Attributes.Add("OnChange", "javascriptcode");
this.viewBiz.MyFieldName.Attributes.Add("OnChange", "javascriptcode");
MyFieldName.Attributes.Add("OnChange", "javascriptcode");

but none of the above seam to be the right way to reference the object.

Does anyone know the correct way of doing this, it feels like it should be a simple thing to do.

Thanks,
Tim

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 12/20/2010 1:05:58 PM
   
RE:Adding Javascript to Bizform field
Hi,

The described approach is not that easily possible in BizForms/FormEngine.
Better way will be to use javascript to find controls and change their onchange attributes in the custom layout of BizForm's Alternative form.

You can create custom form and in the source view of the layout use constructions like:


<table>
...
<tr>
<td>$$label:myField$$</td>
<td><span id="myCustomField">$$input:myField$$</span><br />
$$validation:myField$$</td>
</tr>
...
</tbody>
</table>

<script type="text/javascript" language="javascript">
//<![CDATA[
var customFieldContainer = document.getElementById('myCustomField');
var field = customFieldContainer.getElementByTagName('input')[0];
field.onChange = function(){
/* code here */
};

//]]>
</script>


Hope this will help.

Regards,
Zdenek