Archive

Archive for the ‘javascript’ Category

HOw to add or remove javascript event dynamically

ElementId.EventName returns the corresponding event handing code.
The following code dynamically remove onmouseover event from td element & can add the event of the fly.

var event;
function over(){
alert(‘over’);
alert(document.getElementById(‘tid’) );
event = document.getElementById(‘tid’).onmouseover;
document.getElementById(‘tid’).onmouseover = null;
}
function out(){
alert(‘out’);
//document.getElementById(‘tid’).onmouseover = event;

}

add/remove js event dynamically
Categories: javascript

using typeof operator to gurantee the value of a variable

It checks whether a variable has been set.
I got it from somewhere else.

if (!(typeof worldHasEnded == “undefined”)) {
document.write(“YUP.”);
} else {
document.write(“NOPE.”);
}

dynamically adding element with html page

1.
2.
3. Dynamically add Textbox, Radio, Button in html Form using JavaScript
4.
5. function add(type) {
6.
7. //Create an input type dynamically.
8. var element = document.createElement(“input”);
9.
10. //Assign different attributes to the element.
11. element.setAttribute(“type”, type);
12. element.setAttribute(“value”, type);
13. element.setAttribute(“name”, type);
14.
15. var foo = document.getElementById(“fooBar”);
16.
17. //Append the element in page (in span).
18. foo.appendChild(element);
19.
20. }
21.
22.
23.
24.
25.

Dynamically add element in form.


26. Select the element and hit Add to add it in form.
27.

28.
29. Button
30. Textbox
31. Radio
32.
33.
34.
35.
36.  
37.
38.
39.
40.

original link:http://viralpatel.net/blogs/2009/01/dynamic-add-textbox-input-button-radio-element-html-javascript.html

Categories: javascript