How to create a textarea dependant on flag in javascript

R

Ross

When I sometimes want to debug something on a browser without a firebug
console, I have been using a textarea to which I can print stuff.

So my HTML calls my big script file, and further down in my HTML I put
up a textarea. When a 'debug' condition in my .js is in modeOne, I
write msgs to that textarea. When it's in modeTwo, I write to the
firebug console, in modeThree no messages get written.

I'd like to have that textarea not visible in the latter two modes.

SO my html contains:

<html>
....
<script type='application/x-javascript' src='/myfiles/dowork.js'>
</script>
....
other html
....
<form name="mydebug">
DEBUG Data:
<textarea rows="40" cols="30" name="outdebg"> Debug msgs:
</textarea>

</form>
</html>


Is there some means to make that form part display conditionally? Any
suggestions for a newbie? I suppose moving it into the javascript makes
sense, where an if-statement can be used. But then how does one make a
textarea like that show up?

Thanx

Ross.
 
D

David Mark

When I sometimes want to debug something on a browser without a firebug
console, I have been using a textarea to which I can print stuff.

You mean without an error console. Firebug is optional.
So my HTML calls my big script file, and further down in my HTML I put
up a textarea.   When a 'debug' condition in my .js is in modeOne, I
write msgs to that textarea. When it's in modeTwo, I write to the
firebug console, in modeThree no messages get written.

I'd like to have that textarea not visible in the latter two modes.

That is sensible.
SO my html contains:

No doctype?
<html>
...
<script type='application/x-javascript' src='/myfiles/dowork.js'>
type="text/javascript"

</script>
...
other html
...
<form name="mydebug">
        DEBUG Data:

Put that in a label.
         <textarea rows="40" cols="30" name="outdebg"> Debug msgs:
</textarea>

</form>
</html>

Is there some means to make that form part display conditionally?  Any

Yes, the simplest way is to use the document.write method.

https://developer.mozilla.org/en/DOM/document.write

You could also create the form using document.createElement and add it
to the DOM with appendChild. Unfortunately, IE makes this method more
difficult than it should be.
 
R

Ross

David said:
On Nov 4, 2:48 pm, Ross <[email protected]> wrote:
You could also create the form using document.createElement and add it
to the DOM with appendChild. Unfortunately, IE makes this method more
difficult than it should be.

Thanks David,

That is the method I went with. I stuck a <div id="makeitHere"> </div>
into my HTML doc, then was able to find that in the javascript and use
the appendChild to stick that text area in there precisely where I
wanted it. Works great.

Now I have a flag I can set to say whether I am on FF with firebug
loaded, in which case all my debug messages go to that console. When in
another browser without firefox & a console, the flag is set
differently and the textarea pops up and all my error messages go into
that textarea.

I don't use IE at all, so any extra complexities from those
troublemakers aren't an issue ;-)

Ross.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,262
Messages
2,571,058
Members
48,769
Latest member
Clifft

Latest Threads

Top