View Single Post
Old 08-14-2009, 07:45 AM   PM User | #2
Amphiluke
Regular Coder

 
Amphiluke's Avatar
 
Join Date: Jul 2009
Posts: 312
Thanks: 3
Thanked 89 Times in 89 Posts
Amphiluke is on a distinguished road
Here you are:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
   <meta http-equiv="content-type" content="text/html;charset=utf-8" />
   <title>Template</title>

   <style type="text/css">
      .hilightkw {
         color: #0000FF;
      }
      .hilightcomm {
         color: #008000;
      }
   </style>
   
<script type="text/javascript">
   var vbKeywords = new Array("If","Then","Else","ElseIf","End");
   function HiLightCode(codeBlock) {
      var _code = codeBlock.innerHTML;
      var re = / /g;
      _code = _code.replace(re, "&nbsp;");
      for (var i = 0; i < vbKeywords.length; i++) {
         var re = new RegExp(vbKeywords[i], "gi");
         _code = _code.replace(re, "<span class=\"hilightkw\">" + vbKeywords[i] + "</span>");
         delete re;
      }
      var lines = _code.split("\n");
      var outputCode = "";
      for (var i = 0; i < lines.length; i++) {
         var re = new RegExp("('.+)");
         outputCode += lines[i].replace(re, "<span class=\"hilightcomm\">$1</span>") + "<br />";
         delete re;
      }
      codeBlock.innerHTML = outputCode;
   }
   function HiLightAll() {
      var _codes = document.getElementsByTagName("code");
      for (var i = 0; i < _codes.length; i++) {
         if (_codes[i].className == "vb") HiLightCode(_codes[i]);
      }
   }
   window.onload=HiLightAll;
</script>
   
</head>

<body>
<div>
<code class="vb">
If iVar = 1 Then
  Text1.Text = "Satu" 'This is comment
ElseIf iVar = 2 Then
  Text1.Text = "Dua"
End If
</code>
<code class="vb">
If iVar = 1 Then
  Text1.Text = "Satu" 'This is comment
ElseIf iVar = 2 Then
  Text1.Text = "Dua"
End If
</code>
</div>

</body>

</html>
Note that use the same ids in several objects is not valid.
__________________
I am still learning English
Amphiluke is offline   Reply With Quote
Users who have thanked Amphiluke for this post:
orgbiz (08-19-2009)