DHTMLX Docs & Samples Explorer

Template

Source
<!DOCTYPE html>

<html>
<head>
	<title>Template</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link rel="stylesheet" type="text/css" href="../../../codebase/dhtmlx.css"/>
	<script src="../../../codebase/dhtmlx.js"></script>
	<style>
		div.simple_bold {
			margin: 2px 0px;
			padding: 1px 0px;
			font-weight: bold;
		}
		div.simple_link {
			margin: 2px 0px;
			padding: 1px 0px;
		}
	</style>
	<script>
		var myForm, formData, t=false;
		function doOnLoad() {
			formData = [
				{type: "settings", position: "label-left", labelWidth: 100},
				{type: "template", name: "product", label: "Product:", value: "dhtmlxForm", format:format_a},
				{type: "template", name: "link", label: "Visit our site:", value: "dhtmlx.com", format:format_a},
				{type: "template", label: "Advanced:", value: "Click me!", format:format_b}
			];
			myForm = new dhtmlXForm("myForm", formData);
		}
		function format_a(name, value) {
			if (name == "product") return "<div class='simple_bold'>"+value+"</div>";
			if (name == "link") return "<div class='simple_link'><a href='http://"+value+"' target='blank'>"+value+"</a></div>";
		}
		function format_b(name, value) {
			// to access form instance from format function
			// you cann use the following method:
			// var form = this.getForm();
			return "<div class='simple_link'><a href='javascript:void(0);' onclick='custom_func();'>"+value+"</a></div>";
		}
		function custom_func() {
			t = !t;
			myForm.forEachItem(function(name){
				myForm.setItemLabel(name, (myForm.getItemLabel(name))[t?"toLowerCase":"toUpperCase"]());
			});
		}
	</script>
</head>
<body onload="doOnLoad();">
	<div id="myForm" style="height:100px;"></div>
</body>
</html>