Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #26554

Dynamically add/remove code in browsers

From "Leonardo Azpurua" <leonardo@exmvps.org>
Newsgroups comp.lang.javascript
Subject Dynamically add/remove code in browsers
Date 2015-01-12 05:22 -0430
Organization A noiseless patient Spider
Message-ID <m905b3$90j$1@dont-email.me> (permalink)

Show all headers | View raw


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?

Back to comp.lang.javascript | Previous | Next — Next in thread | Find similar | Unroll thread


Thread

Dynamically add/remove code in browsers "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-01-12 05:22 -0430
  Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 17:21 +0100
    Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-01-12 16:44 -0200
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 22:01 +0100
        Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com> - 2015-01-12 22:06 -0200
          Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-13 01:11 +0100
    Re: Dynamically add/remove code in browsers "Leonardo Azpurua" <leonardo@exmvps.org> - 2015-01-12 15:21 -0430
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-12 22:03 +0100
    Re: Dynamically add/remove code in browsers Joao Rodrigues <groups_jr-1@yahoo.com.br> - 2015-01-13 12:17 -0200
      Re: Dynamically add/remove code in browsers Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2015-01-13 20:50 +0100

csiph-web