473,395 Members | 1,999 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

JavaScript Scratch Pad Design

Claus Mygind
571 512MB
I have a question on using the DOM method - But first let me describe what I am doing.

1. I create on all my forms a generic <div id='scratchPad'> </div>

2. I reuse the scratch pad to display various results, such as searches, browse, about and other intermediate result sets in various formats. Therefore objects like the buttons "Next" and "Prev" do not always exist in the DOM.

Question then, Am I just hogging memory in the browser by creating these objects even if I don't use them? Or can I even create them at all, if they do not exists until dynamically created when needed?
Apr 18 '11 #1

✓ answered by Dormilich

So to create an object in the DOM cannot be done if the object is not going to appear on the screen?
that’s not related, DOM is just an API. the DOM defines the methods to work with an XML(-like) document in JavaScript (or other languages). whether a through DOM created object appears on screen is no concern to the DOM, although you (often) need the DOM to make something appear on screen. as example, you can create a paragraph node (document.createElement("p")), but unless you insert it in the current document’s DOM tree (.appendChild(elem)), it’s "invisible".

4 1967
Dormilich
8,658 Expert Mod 8TB
1. I create on all my forms a generic <div id='scratchPad'> </div>
IDs must be unique!

2. I reuse the scratch pad to display various results, such as searches, browse, about and other intermediate result sets in various formats. Therefore objects like the buttons "Next" and "Prev" do not always exist in the DOM.
OK, you lost me there.
Apr 18 '11 #2
Claus Mygind
571 512MB
Ok overlook any bad coding practice I may be doing here, but this is how I add the generic <div> to each form
Expand|Select|Wrap|Line Numbers
  1. /*
  2. Scratch Pad Functions Section
  3. ---------------------------------------------------
  4.  this function adds a hidden division to a form
  5.  which can be used to popup information or data
  6.  It would be called from myStartUp the body onload
  7.  event handler
  8. ---------------------------------------------------
  9. */
  10. function addScratchPad(obj)
  11. {
  12.     document.getElementById( obj.document.body.id ).innerHTML += 
  13.         '<div '+
  14.         '  id="scratchPad" '+
  15.         '  align="center" '+
  16.         '  style="position:absolute; '+
  17.         '  visibility:hidden; '+
  18.         '  z-index:99;" '+
  19.         '> '+
  20.         '    <table style="padding:0px; margin:0px;" width="100%"> '+
  21.         '        <tr><td> '+
  22.         '            <button id="closePad" '+ 
  23.         '                type="button" '+
  24.         '                style="padding:0px; float:right; background-color:blue,color:yellow;"'+
  25.         '                onclick="showHideScratchPad(); return false;">'+
  26.         '                <IMG SRC="/ABC/images/closeButton.gif" style="height:16px;width:16px;">'+
  27.         '            </button><br/><br/>'+
  28.         '        </td></tr><tr><td> '+
  29.         '            <table name = "sPadTable" id = "sPadTable" align="center"> '+
  30.         '                <tbody id="sPadData" ></tbody>'+
  31.         '            </table>'+
  32.         '        </td></tr> '+
  33.         '    </table>'+
  34.         '</div>';
  35.  
  36. }
  37.  
  38.  
  39.  
This routine is located in my basic nav.js file I attache to all my forms.

When I want to use it I pass it the parameter, I need to display the scratch pad. When I close scratch pad, I simply clean it out.

Expand|Select|Wrap|Line Numbers
  1. /*
  2. -----------------------------------------------------------------------------------------
  3. Display or hide scratch pad
  4.  
  5. usage:
  6. onclick = "showHideScratchPad(left,top,height,width[,cBgColor,cBstyle,cBwidth,cBcolor]);"
  7.  
  8. the first 4 parameter are mandatory, 
  9. if any of the 4 remaining parameters are used
  10. they must be supplied in order specified.
  11. if an optional parameter is not used but 
  12. others are all preceeding parmeters must
  13. be given as false.
  14.  
  15. no parameters are needed to turn off the
  16. scratch pad.
  17. onclick = "showHideScratchPad();"
  18. -----------------------------------------------------------------------------------------
  19. */
  20. function showHideScratchPad(cLeft,cTop,cHeight,cWidth,cBgColor,cBstyle,cBwidth,cBcolor) 
  21. {
  22.     if (  document.getElementById("scratchPad").style.visibility == "hidden" ) {
  23.         document.getElementById("scratchPad").style.backgroundColor = ( !cBgColor ) ? "#E4BF87" : cBgColor ;
  24.         document.getElementById("scratchPad").style.borderStyle = ( !cBstyle ) ? "ridge" :cBstyle ;
  25.         document.getElementById("scratchPad").style.borderWidth = ( !cBwidth ) ? "5px" : cBwidth ;
  26.         document.getElementById("scratchPad").style.borderColor = ( !cBcolor ) ? "orange" : cBcolor;
  27.         document.getElementById("scratchPad").style.zIndex = "101";
  28.         document.getElementById("scratchPad").style.visibility = "visible";
  29.         document.getElementById("scratchPad").style.overflow = "auto";
  30.         document.getElementById("scratchPad").style.left =  cLeft;
  31.         document.getElementById("scratchPad").style.top = cTop;
  32.         document.getElementById("scratchPad").style.height = cHeight;
  33.         document.getElementById("scratchPad").style.width =  cWidth;
  34.     }else{ //hide if visible
  35.         document.getElementById("scratchPad").style.visibility = "hidden";
  36.         document.getElementById("scratchPad").style.left =  "0px";
  37.         document.getElementById("scratchPad").style.top = "0px";
  38.         document.getElementById("scratchPad").style.height = "0px";
  39.         document.getElementById("scratchPad").style.width =  "0px";
  40.         // remove existing rows, if any
  41.         while (document.getElementById("sPadData").rows.length > 0) 
  42.         {
  43.             document.getElementById("sPadData").deleteRow(0);
  44.         }
  45.     }
  46. }
  47.  
When a result set is returned from the server, I create and load a table on the scratchPad, then I call the display of the Pad itself.
Expand|Select|Wrap|Line Numbers
  1.             displayBrowser(form, aCallBack);
  2.             showHideScratchPad(form.left,25, form.screenHeight, form.screenWidth,'#95E3E3');    
  3.  
Here are a couple of screen shots showing different information being displayed.







As you can see the Next and Prev buttons are not always used. Also the inner table used to display the data has different names.

So to create an object in the DOM cannot be done if the object is not going to appear on the screen?
Apr 18 '11 #3
Dormilich
8,658 Expert Mod 8TB
So to create an object in the DOM cannot be done if the object is not going to appear on the screen?
that’s not related, DOM is just an API. the DOM defines the methods to work with an XML(-like) document in JavaScript (or other languages). whether a through DOM created object appears on screen is no concern to the DOM, although you (often) need the DOM to make something appear on screen. as example, you can create a paragraph node (document.createElement("p")), but unless you insert it in the current document’s DOM tree (.appendChild(elem)), it’s "invisible".
Apr 18 '11 #4
Claus Mygind
571 512MB
From your answer that would suggest that creating the DOM object would then be a memory hog if it is not going to be used.

Yes one item may not be much of a hog. But using this scenario, I would have to create all the possible objects just in case they are going to be used.

I think I prefer creating them on the fly.

Your explanation has been very helpful and I now see where I can improve other parts of my apps.

As always thank you for the great help
Apr 18 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: annon | last post by:
I've noticed that some problems come up frequently that are of importance in writing web pages, because they're pretty fundamental points. For general reference, here are some collected...
136
by: Matt Kruse | last post by:
http://www.JavascriptToolbox.com/bestpractices/ I started writing this up as a guide for some people who were looking for general tips on how to do things the 'right way' with Javascript. Their...
21
by: petermichaux | last post by:
Hi, I've been asking questions about library design over the last week and would like to get feedback on my overall idea for a JavaScript GUI library. I need a nice GUI library so there is a...
1
by: Darrel | last post by:
I'm try to put some server-side (codebehind) variables in my javascript. Something like this: <script language='JavaScript'> var monkey = <asp:literal runat="server"...
7
by: Wm.M.Thompson | last post by:
For a computer programmer JavaScript is not difficult. It is pretty easy to look at some code for the first time and figure out what is going on. This is especially true if you have gratuated...
18
by: Tom Cole | last post by:
I'm working on a small Ajax request library to simplify some tasks that I will be taking on shortly. For the most part everything works fine, however I seem to have some issues when running two...
3
by: Amnon | last post by:
Hi, I'd like to announce release 1.0.7 of JNEXT (JavaScript Native Extensions). JNEXT is an open source framework for securely accessing the full range of native OS resources (files, databases,...
22
by: Dan Rumney | last post by:
Hi all, I've been writing Javascript for quite a while now and have, of late, been writing quite a lot of AJAX and AJAX-related code. In the main, my dynamically generated pages are created...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.