Thursday, June 30, 2011

How to use getElementById

From.. 
http://www.javascript-coder.com/javascript-form/getelementbyid-form.phtml
http://www.tizag.com/javascriptT/javascript-getelementbyid.php



Sample code
Download the sample code here: getelementbyid-form-sample.zip
There are many ways of accessing form elements, of which the easiest is by using the cross-browser W3C DOM document.getElementById() method. Before we learn more about this method, it would be useful to know something about the Document Object Model (DOM), the concept of HTML nodes or elements, and the concept of containers.

Each time you load an HTML page, the web browser generates an internal representation of the page in the form of an inverted tree structure. Let us look at a simple form. We will use this form later to demonstrate the use of the getElementById method.
<form name ="subscribe" id="subscribe_frm" action="#">
Your Name: <input type="text" name="name" id="txt_name" />
Your Email: <input type="text" name="email" id="txt_email" />
<input type="button" name="submit" value="Submit"
onclick="processFormData();" />
</form>
There are elements such as <input/> and containers like <form> </form> Each element can have attributes associated with it, such as:
<input type="text" name="name" id="txt_name">
Here, the <input/> element has three attributes: type, name and id. The id attribute uniquely identifies this particular element.

Accessing Form Elements using getElementById

In order to access the form element, we can use the method getElementById() like this:
var name_element = document.getElementById('txt_name');
The getElementById() call returns the input element object with ID ‘txt_name’ . Once we have the object, we can get the properties and call the methods of the object. For example, to get the value of the input element, get the value attribute.
var name = name_element.value;
Similarly, it is possible to access the <form> element:
var frm_element = document.getElementById ('subscribe_frm');

Example: access the form and input elements

See the demo.
In this demo, we toggle the visibility of the form. This is done by accessing the form element <form> which we have seen above and setting its display property as shown in the code below:
var frm_element = document.getElementById('subscribe_frm');
var vis = frm_element.style;
if (vis.display=='' || vis.display=='none')
{
    vis.display = 'block';
}
else
{
    vis.display = 'none';
}

Example: Input validation

The code below makes sure that the field is not empty.
First, we trim out any leading and trailing blank space.
function trim (str)
{
     return str.replace (/^\s+|\s+$/g, '');
}
The code below validates the txt_name field.
var name_element = document.getElementById (‘txt_name’);
if (trim(name_element.value) == '')
{
   alert ('Please enter your name');
}

Checking for getElementById support

All modern browsers support getElementById() method. However if you are to support very old browsers, use the following function:
function getElement (id)
{
   if (document.getElementById)
   {
      return document.getElementById(id);
   }
   else if (document.all)
   {
      return window.document.all[id];
   }
   else if (document.layers)
   {
      return window.document.layers[id];
   }
}

Other Cross-browser ways of accessing form element objects

There are two other cross-browser ways of accessing form elements: document.getElementsByTagName and document.getElementsByName.

Using the document.getElementsByTagName Method

This method takes in as argument the name of a tag (element) and returns an array of all matching tags (elements) found in the document.
In our form example, if we had to get a reference to all the <input> elements, we could use the following code:
var inputs = document.getElementsByTagName('input');
The variable inputs is a reference to an array of all <input> elements including: <input type=”button”>
getelementbyid example 2
What if we only wanted to access <input> elements with the type attribute as text? We could do it in the following way:
var inputs = document.getElementsByTagName("input");
var message =
   "The form has the following input elements with the 'type' attribute = 'text': \n\n";
for (var i=0; i < inputs.length; i++)
{
   if (inputs[i].getAttribute('type') == 'text')
   {
      message += inputs[i].tagName +
      " element with the 'name' attribute = '";
      message += inputs[i].getAttribute('name') + "'\n";
   }
}
alert(message);
This time, the elements retrieved do not include the element: <input type=”button”>.
getelementbyid example 3

Using the document.getElementsByName Method

This method takes in as argument the name attribute value of elements to be retrieved and returns a collection of desired matching elements.
In the code snippet below, let us say we need to get a reference to the <select> element with the name attribute mail_format.
<select name="mail_format" id="slt_mail_format">
<option value="TEXT">Plain Text</option>
<option value="HTML">HTML</option>
</select>
We could access the desired element in this way:
var mail_format_elements = document.getElementsByName('mail_format');
getelementbyid example 4.

Javascript

http://homepage.ntlworld.com/kayseycarvey/


<HTML>
<HEAD>
<TITLE>A First Script</TITLE>
</HEAD>
<BODY>
    <SCRIPT LANGUAGE = JavaScript>
        document.write("Hello World")
    </SCRIPT>
</BODY>
</HTML>

- Document is part of something called the Document Object Model. Document refers to all the text and HTML elements between the two BODY tags. And that includes any attributes inside the BODY tag itself. Like BGCOLOR.

- Write( ) is a method of Document. A method is a bit of code that actually does something. As opposed to a Property, which IS something. Methods are usually Verbs, and Properties usually Nouns. The Write( ) method writes text (and numbers as well) between the two BODY tags on your page. So the whole line reads "Write the text Hello World between the two BODY tags of the web page."

- At the moment, we have our script between the two BODY tags. And it works perfectly well here. It's quite happy where it is. However, SCRIPTS are best kept in the HEAD section of your HTML. This is because any code in the HEAD section will be dealt with first by the browser. And besides, it's neater up there. You're not cluttering up your HTML code with lots of JavaScript.

The Pop-up message box (Alert boxes)

<HTML>
<HEAD>
<TITLE>A First Script</TITLE>
    <SCRIPT LANGUAGE = JavaScript>
        document.write("hello World")
    </SCRIPT>
</HEAD>
<BODY>
<INPUT TYPE = Button VALUE = "Click Me" OnClick = "alert('That was not a proper email address')">

</BODY>
</HTML>

Properties
  • bgColor
  • fgColor
  • title
  • location
  • images
  • forms
Methods
  • open()
  • close()
  • write()
  • writeln() 

Vizard - vizhtml

Form Definition

To define forms, you must use the HTML <form> tag. All input elements defined within the <form> tag will be included in the data of the form submission event.

A couple important things to note when defining your HTML form:

  1. You must set the method attribute of the form to "post"
  2. If your HTML is specified in an external file/URL, as opposed to embedded in your script, you must set the action attribute to the vizhtml web server (e.g. "http://localhost:8080/vizhtml_form/")
vizhtml.displayCode(html)

# Wait for form submission
d = yield vizhtml.waitFormSubmit()
# Get data from form
first = d.first_name
last = d.last_name

viztask.schedule( FormTask() )



HTML forms in a remote browser

In order to collect data from an HTML form displayed in a remote browser, a page containing HTML content needs to be registered with vizhtml's local HTTP server. A form submission event will get triggered once a form is submitted and data can be collected using a task or callback function. 

vizhtml.registerCode('form_submit',code)

def HandleForm(e):
    print e.first_name,e.last_name
vizhtml.onFormSubmit(HandleForm)  





Local HTTP server and URLs

- All the communication that occurs between Vizard and a browser or embedded HTML page, whether through forms or WebSocket messages, goes through a local HTTP server built into vizhtml. The commands listed in previous sections to display HTML in the embedded window and register HTML with the local HTTP server automatically start the server.
- The base URL of vizhtml's HTTP server is the default server port (8080) affixed to the computer name or IP address of the machine. The full URL of a page on the server is a combination of the base URL of the server + /vizhtml/ + the page URL.




Collecting form data

- When an HTML form in a remote browser or embedded HTML window is submitted, a vizhtml.FORM_SUBMIT_EVENT is generated. The event can be handled using either a task or callback function.

vizhtml.waitFormSubmit()        Waits until a form submit event occurs. The yielded command returns a viz.Data object that holds the form data.

vizhtml.onFormSubmit(func,
*args,
**kw)
   Registers a callback function for a form submission event:

func: The function being registered. An event object e, holding form data, will be passed to this callback function.

*args: Optional arguments to pass to the registered function.

**kw: Optional keyword arguments to pass to the registered function.


WebSocket communication

- Real time bidirectional communication between Vizard and a web browser is supported using WebSockets. You can send and receive messages and find out when socket connections open or close. On the server (Vizard) side, the vizhtml module provides Vizard commands for sending messages and handling message and connection events. Similar functionality is provided on the client (browser) side using JavaScript functions through vizhtml's JavaScript library.

Wednesday, June 29, 2011

GLSL - Introduction - Related webpages

(Credit to the following page.)
http://loger1000.springnote.com/pages/3687031



 opengl.org 의 shading language

http://www.opengl.org/code/category/C20


The art of texturing Using the OpenGL Shading Language
  1. home : http://www.ozone3d.net/tutorials/glsl_texturing.php
    1.  tutorial : http://www.ozone3d.net/tutorials/index_glsl.php

  Fog with GLSL
    Fog implementation using GLSL - Use of gl_FogFragCoord, gl_FragCoord, gl_FogCoord and gl_Fog variables.

  How to bypass a Catalyst 7.11/7.12 GLSL Bug
    This article shows a workaround of a GLSL bug present in the Catalyst drivers 7.11 and 7.12.

  Mesh Deformers
    Two examples of mesh deformers using the GPU: surface deformer and mesh twister.

  The Art of Texturing using the GLSL
    This tutorial shows the common techniques of texturing and their implementation with GLSL (simple and multtexturing, sphere mapping, dual paraboloid mapping, cube mapping, texture warping, projective texture mapping).

  Vertex Displacement Mapping
    Explanation of the vertex displacement mapping technique to deform a mesh using a texture look up from a vertex shader.

  Normal-Map Compression
    The problem of normal-map (or bump-map) compression and how to solve it (renormalization - swizzled-DXT5 - ATI 3Dc).

  Lighting in GLSL - Phong Model
    This article presents the Phong lighting model and its implementation in GLSL for point and spot lights.

  The Mandelbrot Set: Colors of Infinity
    Theory and implementation on GPU with GLSL of Mandelbrot fractal rendering. Introduction to GPGPU.

  Image Filtering
    Image filtering and GLSL filters implementation (convolution kernels).

  Ambient Occlusion Lighting
    Présentation of ambient occlusion lighting technique. Occlusion-maps creation. Ambient occlusion GLSL shader.

  Bump Mapping
    Bump mapping implementation using GLSL shader. Lighting equations. Tangent space.

  Normal-maps
    Presentation and creation of normal-maps (or bump-maps).

  S3TC Texture Compression
    Texture compression (S3TC - DXT1/5) and how use it in Demoniak3D.

  Introduction to GLSL
    This tutorial presents the basis about GLSL shading language. GLSL shader integration into Demoniak3D.

2. demo : http://www.ozone3d.net/demos_projects/old_building.php#downloads

[+] Toon Snow
 
Merry Christmas with cel-shading and particles.

Executable: [ YES ]
Code Source: [ YES ]

Features:
- GLSL Cel-Shading
- OpenGL 1.5
- Particles

[+] Ageia PhysX Pendulum
 
Demo showing how to use the Ageia PhysX engine 'distance joints'.

Executable: [ YES ]
Code Source: [ YES ]

Features:
- Ageia PhysX functions
- LUA
- Mesh Picking
- OpenGL 1.3
- Shadow-volume

[+] Spiral Galaxy
 
Simulation of a spiral galaxy.

Executable: [ YES ]
Code Source: [ YES ]

Features:
- LUA
- vertex pool

[+] High Resolution Skyboxes
 
DemoPack of high resolution skyboxes.

Executable: [ YES ]
Code Source: [ YES ]

Features:
- Skybox 2k and 4k.

[+] Kool Fire
 
Demo of a small fire with smoke...

Executable: [ YES ]
Code Source: [ YES ]

Features:
- GLSL
- OpenGL 1.5
- Particles
- LUA
- Sound

[+] 3DGurukul Models DemoPack
 
Set of Demoniak3D demos showing 3DGurukul's free models.

Executable: [ NO ]
Code Source: [ YES ]


[+] PimPim's Siu Nim Tao
 
Demoniak3D Demo - Character animation and toon shader.

Executable: [ YES ]
Code Source: [ YES ]

Features:
- GLSL
- OpenGL 1.5
- Character Animation using keyframes


[+] Chromatic Aberration
 
Demo showing a reflexion / refraction shader with light dispersion.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- GLSL
- OpenGL 1.5
- Gloss map
- Cube Map
- Reflection / Refraction gpu shader


[+] Mandelbrot Fractal
 
Demo showing Mandelbrot fractal generation using GPGPU (General Programming on GPU) techniques.

Executable: [ NO ]
Source Code: [ YES ]

Features:
- LUA
- GLSL
- FBO
- GPGPU concepts
- OpenGL 1.5


[+] Merry Christmas
 
The last demo of the year 2005 and the first one of 2006! Ambient occlusion and bump mapping, snow and merry christmas & happy new year!

Executable: [ NO ]
Source Code: [ YES ]

Features:
- LUA
- GLSL Ambient Occlusion Lighting Bump Mapping
- Particle System
- OpenGL 1.5


[+] Static Ambient Occlusion
 
Demo using an Ambient Occlusion Lighting and bump mapping shader, a water reflexion shader and point_sprite particles.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- LUA
- GLSL Ambient Occlusion Lighting
- GLSL Bump Mapping
- Particle System (point_sprite mode)
- water reflexion shader
- OpenGL 1.5


[+] Lost Church
 
Demo using shadow volumes, particle system, bump mapping shaders. Shows how to setup the basis of a FPS game (First Person Shooter).

Executable: [ NON ]
Source Code: [ OUI ]

Features:
- LUA
- Stencil Shadow Volumes
- Sound
- Particle System
- GLSL Bump Mapping
- OpenGL 1.5


[+] Suffocate Benchmark
 
Benchmark using shadow volumes, particle system, and synchronized gfx/musik.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- LUA
- Stencil Shadow Volumes
- Sound
- Particle System
- OpenGL 1.2


[+] Private Museum
 
Demo using shadow volumes and dynamic attenuated lights.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- Stencil Shadow Volumes
- Attenuated lights
- OpenGL 1.2


[+] Water Reflexion
 
Demo exploiting a water reflexion shader.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- GLSL
- OpenGL 1.5


[+] Buggy
 
Demo showing the use of opacity-maps in order to get partial-reflexions.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- OpenGL 1.3
- spherical mapping
- texture reflexion
- VBO
- dynamic lighting


[+] IceFire
 
Particle system demo.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- Particle System
- OpenGL 1.2


[+] Djizoes - Second Thoughts
 
'Second Thoughts' sound track demo of Djizoes group.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- Sound
- Env sphere mapping
- OpenGL 1.2


[+] Parallax Bump Mapping
 
Demo showing a parallax bump mapping shader.

Executable: [ YES ]
Source Code: [ YES ]

Features:
- parallax bump mapping shader
- OpenGL 1.5
 OpenGL Shading Language course
  1. home : OpenGL Shading Language course