Leonardo Azpurua
1/12/2015 8:52:00 AM
Hi,
I am planning to implement a Web interface for a rich/fat client Windows
business system.
In its current implementation, the system allows searching whenever the Id
of an entity is required, and new entities can be created "in-line" by
provided a valid, non-existant id.
Now, in some forms, there may several kinds of entitites (items, customers,
payment conditions, pricing profiles, salesmen).
It doesn't sound practical to clutter the basic HTML page with all the divs,
code and controls required to manage all the possible creations.
So I am trying to find a way to dynamically add a DIV, give it a "standard
look", populate it with input controls, show it as a sort of modal dialog,
close it and restore the browser to its original state.
As for code, this is a very basic test of an approach:
var sc;
function addHandler() {
var el = document.getElementById("test");
sc = document.createElement("script");
sc.id = "dynScript";
sc.type = "text/javascript";
// the value assigned to the script will be a rather large chunk of
code imported by an httpRequest
sc.text = "function handleClick() { window.alert('Test clicked') }";
document.getElementsByTagName("head")[0].appendChild(sc);
el.onclick = handleClick;
}
function removeHandler() {
var el = document.getElementById("test");
el.onclick = null;
document.getElementsByTagName("head")[0].removeChild(sc);
sc = null;
}
That is:
On Creation:
Have the document create an SCRIPT element, and append it to the HEAD
element (is this necessary?).
Assign the functions to the event handlers of the appropriate controls
(this would be handled by the new code itself)
On Disposing
Remove all the event handlers
Remove the SCRIPT element from the document
Dispose of the script element itself.
Does this sound like a right approach, or am I totally missing it?