473,795 Members | 3,279 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript equivalent of 'data dumper'

hey all,

I'm a heavy perl user, not so much a java script user, and was
wondering...

perl has an extremely nice utility called Data::Dumper, which allows
you to dump out the contents of an arbitrary data structure. I'd like
to do the same with javascript.

print Data::Dumper(do cument)
print Data::Dumper(do cument.form)

etc. etc. etc.

Is there a utility that lets you do this?

Also, is there any particular reason why a function wouldn't be able to
see a certain variable? I'm calling javascript with the form:

<script type="text/javascript" >
function download_submit ()
{
alert(document. form.filecheckb ox.value);
}
</script>

<form name="form">
<a href="javascrip t:download_subm it()">
<img src="...." ...>
</a>

<input name="filecheck box" value="myval" type="checkbox"
onchange="this. form.folderchec kbox.value=this .value"

</form>

For some reason, when I check the checkbox, I don't see the results in
the javascript. I'd like to dump out the document to see exactly *what*
the javascript function is seeing...

Thanks much for any help...

Ed

Jul 23 '05 #1
14 3337
horos wrote:
hey all,

I'm a heavy perl user, not so much a java script user, and was
wondering...

print Data::Dumper(do cument)
print Data::Dumper(do cument.form)

I have never seen anything like this. But if you are using the Mozilla
browser suite there are a ton of plugins for web development, including
DOM inspectors, javascript debuggers, CSS tools, etc. I am thinking
that maybe the DOM inspector would let you do what you are trying to
do.

https://addons.update.mozilla.org/ex...eloper%20Tools

For some reason, when I check the checkbox, I don't see the results in the javascript. I'd like to dump out the document to see exactly *what* the javascript function is seeing...


Well, in your example, when you check the checkbox, the value of
filecheckbox was being re-assigned the value of "myval1", which was the
initial value of filecheckbox, so is this why you weren't seeing a
change, maybe?

I shortened your onclick code a little bit and hard coded a value of
hello, but it works fine for me.

<a href="javascrip t:download_subm it()">Show Alert</a>
<input name="filecheck box" value="myval1" type="checkbox"
onclick="this.v alue='hello'">

I've omitted the javascript function for simplicitly sake, but if you
click the hyperlink "Show Alert" it alerts with "myval1", but if I
check the checkbox and click "Show Alert" it alerts with "hello"

-- brian

Jul 23 '05 #2
yes, I changed onchange to onclick, and it worked... Thanks.

As far as the Dumper item goes, I tried DOM inspectors, and they seem
to work great on the HTML side of the fence, but not on the JavaScript
side. They parse the HTML to come up with the tags, but don't do the
heavy lifting of finding out what javascript interpreter a given
browser is using and then going in to find its attributes and their
values.

A pity, really, because this would speed up my development by at least
an order of magnitude, if not more. If anyone knows of something like
this, I'd love to hear about it.

Cheers,

Ed

Jul 23 '05 #3
horos wrote:
[...]
Also, is there any particular reason why a function wouldn't be able to
see a certain variable? I'm calling javascript with the form:

<script type="text/javascript" >
function download_submit ()
{
alert(document. form.filecheckb ox.value);
alert(document. forms.filecheck box.value);
------------------------------^

Simple syntax error, you are addressing the *forms* collection.

[...] <input name="filecheck box" value="myval" type="checkbox"
onchange="this. form.folderchec kbox.value=this .value"
> </form>

For some reason, when I check the checkbox, I don't see the results in
the javascript. I'd like to dump out the document to see exactly *what*
the javascript function is seeing...


Onchange is kinda nasty with a checkbox. According to the HTML spec,
onchange fires when the element loses focus. But this doesn't really
make sense with a checkbox, so Geko browsers fire the onchange
essentially as an onclick. IE, on the other hand, follows the spec
and fires the onchange when the checkbox loses focus.

This is very confusing as if you have say 3 checkboxes with different
onchange events, when you click one nothing happens, when you click
the next one the onchange from the first on you clicked fires, when
you click somewhere else in the page, the second one fires. The user
associates the event with the following click, not the one that
actually causes the event to happen, hence confusion.

The solution is to use onclick and check the state of the checkbox to
see if it's checked or not, then run the event or not. Something
like:

<input ... type="checkbox" onclick="
this.form.folde rcheckbox.value = (this.checked)? this.value : '';
">

Thanks much for any help...


No problem.
--
Rob
Jul 23 '05 #4
RobG wrote:
horos wrote:
[...]
Also, is there any particular reason why a function wouldn't be able to
see a certain variable? I'm calling javascript with the form:

<script type="text/javascript" >
function download_submit ()
{
alert(document. form.filecheckb ox.value);

alert(document. forms.filecheck box.value);
------------------------------^


Simple idiot error: I didn't notice you'd called your form 'form'.
Forget the above.

--
Rob
Jul 23 '05 #5
horos wrote:
perl has an extremely nice utility called Data::Dumper, which allows
you to dump out the contents of an arbitrary data structure. I'd like
to do the same with javascript.


heh, your prayers are answered :)

http://www.mattkruse.com/javascript/datadumper/

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #6
Matt Kruse wrote:
horos wrote:
perl has an extremely nice utility called Data::Dumper, which allows
you to dump out the contents of an arbitrary data structure. I'd like
to do the same with javascript.

heh, your prayers are answered :)

http://www.mattkruse.com/javascript/datadumper/


Hey Matt, your script makes the claim:

"COMPATABIL ITY: Will work in any javascript-enabled browser "

but the example doesn't work in either Safari or Firefox on
OS X 10.2.8.

Over to you.

--
Fred
Jul 23 '05 #7
horos wrote:

[snip]
As far as the Dumper item goes, I tried DOM inspectors, and they seem
to work great on the HTML side of the fence, but not on the JavaScript
side. They parse the HTML to come up with the tags, but don't do the
heavy lifting of finding out what javascript interpreter a given
browser is using and then going in to find its attributes and their
values.


Are you certain? By default, the DOM inspector displays information
about elements and their attributes. However, it can show other
information, which can be very useful.

To the left of the pane title is a button-activated pop-up menu that
lists the other views for that pane. Note that changing the left-hand
pane will cause the node list for the document tree to disappear. To get
the list back, select the appropriate menu item from the File > Inspect
a Window sub-menu.

As far as I know, the only way to inspect the global object (aka window)
is through the defaultView.win dow property when inspecting the document
(#document) object.

Finally, using the alert function, or a temporary TEXTAREA element, is a
good way of examining the environment, provided you know what you're
looking for. I certainly think it's better than a generic dump.

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #8
Fred Oz wrote:
"COMPATABIL ITY: Will work in any javascript-enabled browser "
but the example doesn't work in either Safari or Firefox on
OS X 10.2.8.


Hmmm, can you give me any details? I don't have the ability to test on macs,
but the code doesn't do anything special, so I'm not sure why it wouldn't
work on those browsers. If you can give me an error message or line number
or any insight into what the problem is, I can try to fix it.
Thanks!

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #9
Matt Kruse wrote:
Fred Oz wrote:
"COMPATABIL ITY: Will work in any javascript-enabled browser "
but the example doesn't work in either Safari or Firefox on
OS X 10.2.8.

Hmmm, can you give me any details? I don't have the ability to test on macs,
but the code doesn't do anything special, so I'm not sure why it wouldn't
work on those browsers. If you can give me an error message or line number
or any insight into what the problem is, I can try to fix it.
Thanks!

Using Firefox (since its error reporting is somewhat superior to
Safari's...) when loading:

<URL:http://www.mattkruse.c om/javascript/datadumper/>

Get error:

Error: uncaught exception: [Exception... "Component returned failure
code: 0x80004005 (NS_ERROR_FAILU RE) [nsIDOM3Node.tex tContent]"
nsresult: "0x80004005 (NS_ERROR_FAILU RE)" location: "JS frame ::
http://www.mattkruse.com/javascript/.../datadumper.js ::
Dumper :: line 186" data: no]
Clicking on the "Alert the structure" link gives the same error,
clicking on "Popup a window with the output" give the same error. A
new window does appear, but I just get the wait cursor. The grey
"results in this" section is just blank.

I got the same result in Camino (no real surprise), but it seems to
work OK in IE 5.2 and Opera 6.0 (which won't even load my favourite
news site 'cos of JS errors) so you must be doing something right.
:-)

I'll poke around a bit tomorrow to see what's going on. Time for
sleep.

--
Fred
Jul 23 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
7145
by: Edward wijaya | last post by:
Hi, Is there any equivalent of it in Python? Thanks so much for your time. Regards, Edward WIJAYA
0
1877
by: kamal | last post by:
I am trying to dump a hash using Data::Dumper. I need to quote the keys while dumping. My progarm looks like this use Data::Dumper; $Data::Dumper::Quotekeys = 1; $Data::Dumper::Useqq = 1; my %tmp ;
0
5299
by: Eric | last post by:
I've got a weird problem, regardless of how often I enter: perl -MCPAN -e 'install "Data::Dumper"' I never get a message telling me that it is up-to-date. It will always try to reinstall even though the installation is apparently successful. Here is the output: CPAN: Storable loaded ok
1
3428
by: Miguel Manso | last post by:
Hi there, I'm a Perl programmer trying to get into Python. I've been reading some documentation and I've choosed Python has being the "next step" to give. Can you point me out to Python solutions for: 1) Perl's Data::Dumper It dumps any perl variable to the stdout in a "readable" way.
0
266
by: tom arnall | last post by:
> George, did you ever put your object dumper on the internet? tom arnall north spit, ca
1
2206
by: rhaas | last post by:
Howdy. I've been trying to parse the return of XML::TreePP from an xBRL file using perl and Data::Dumper. The resulting Data::Dumper output looks like this: $VAR1 = { 'xbrl' => { 'dow:ComprehensiveIncomeloss' => , 'dow:DistributionsFromNonconsolidatedAffiliates' =>
3
7347
KevinADC
by: KevinADC | last post by:
If you are entirely unfamiliar with using Perl to sort data, read the "Sorting Data with Perl - Part One and Two" articles before reading this article. Beginning Perl coders may find this article uses unfamiliar terms and syntax. Intermediate and advanced Perl coders should find this article useful. The object of the article is to inform the reader, it is not about how to code Perl or how to write good Perl code, but to teach the Schwartzian...
0
1124
by: reco | last post by:
Hi, I am only new to development and have been given a task to convert a Perl script to a Windows Service. The issue I am facing is that the current Perl Script uses a SOAP call to an Apache Web Server to retrieve data through https xml feeds. I am unable to locate any help on how to write this in c#. I am using Visual Studios 2005. I have provided part of the Perl Script if it helps (I have altered the proxy and uri for security reasons)....
1
3539
by: srinivasan srinivas | last post by:
Thanks, Srini Bollywood, fun, friendship, sports and more. You name it, we have it on http://in.promos.yahoo.com/groups/bestofyahoo/
0
9672
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10435
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10163
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9037
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6779
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3721
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.