473,804 Members | 3,789 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
14 3340
horos wrote:

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...

Below is a quick prototype document I did a while back to debug forms.
The example traps the onsubmit event for the form, but you can analyze a
form at any point with the included functions. I frequently want to see
what's going to be submitted to the server before it actually goes,
which is why I wrote it. This file isn't complete (there are properties
of elements fetched, but not dumped out and I don't recall if the
shading for disable elements worked in this file or not), but the real
version is now too tightly integrated into my other code to be of much
use as is. Watch for line wrapping (all of my JS should have semicolon
terminators). At the very least it should give you an idea of how to dig
some of this info out yourself.

-------------------------------------
J Wynia
Myriad Intellect, Inc.
"Web technology that earns its keep."
www.myriadintellect.com
-------------------------------------

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Form Dump </title>
<script language="JavaS cript">
<!--
function form_dump($form _name){
$form = document.forms[$form_name];
var newwin =
window.open("", "formdumpwin"," menubar,scrollb ars,resizable,w idth=600,height =400");
newwin.document .write("Form name: " + $form.name + "<br>");
newwin.document .write("Action: " + $form.action + "<br>");
newwin.document .write("Method: " + $form.method + "<br>");
newwin.document .write("Target: " + $form.target + "<br>");
newwin.document .write("Onreset : " + $form.onReset + "<br>");
newwin.document .write("Onsubmi t: " + $form.onSubmit + "<p><hr>");

newwin.document .write("Paramet ers: <br>");

for(var i=0;i<$form.ele ments.length; i++){
//Element information and general attributes
$element = $form.elements[i];
$type = $element.type;
$checked = $element.checke d;
$defaultchecked = $element.defaul tChecked;
$disabled = $element.disabl ed;
$defaultvalue = $element.defaul tValue;
$belongsto = $element.form;
$name = $element.name;
$value = $element.value;
$selectedindex = $element.select edIndex;
$length = $element.length ;
//Event binders
$onclick= $element.onclic k;
$onmouseover = $element.onmous eover;
if($disabled == "true"){
newwin.document .write("<div style='color: grey'>");
}
newwin.document .write("Paramet er name: " + $form.elements[i].name +
"<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Type: " + $type +
"<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Curren t Value: "
+ $value + "<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Checked : " +
$checked + "<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Checke d by
default: " + $defaultchecked + "<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Disable d: " +
$disabled + "<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Selecte dIndex: "
+ $selectedindex + "<br>");
newwin.document .write("&nbsp;& nbsp;&nbsp;&nbs p;&nbsp;Length : " +
$length + "<br>");
if($disabled == "true"){
newwin.document .write("</div>");
}

}

newwin.document .close();
}

function choose_form_dum p(){
var newwin =
window.open("", "chooseformdump ","menubar,scro llbars,resizabl e,width=600,hei ght=400");
newwin.document .write("<b>Avai lable forms:</b> Choose a form to see its
current state<p>");
for(var i=0;i<document. forms.length; i++){
newwin.document .write("<a href='#' onclick=\"self. opener.form_dum p('"+
document.forms[i].name + "');\">" + document.forms[i].name + "</a><br>");

}
}

//-->
</script>
</head>

<body>
<form action="http://localhost/util/formdump.php" name="testform"
method="post" onsubmit="choos e_form_dump();r eturn false;">
<input type="text" name="test" value="whatever ">
<input type="text" name="hideme" value="invisibl e" disabled>
<input type="submit" name="submit">
</form>
</body>
</html>
Jul 23 '05 #11
Fred Oz wrote:
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]


Well I got a chance to test using Safari on a mac and I narrowed it down to
this line:

if (o==window || o==window.docum ent)

Apparently, it doesn't like to compare strings to the window object. This
simple test case fails:

var x = "test";
alert(x==window );

That shouldn't fail with an error, should it?

Comparing an <OPTION> object to the window object crashes the browser
completely.

Unless someone can justify why a browser should generate an error when
comparing an arbitrary object to the window object, I'll consider it a bug
in Mac browsers and ignore it :)

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #12
Matt Kruse wrote:
<snip>
Well I got a chance to test using Safari on a mac and I
narrowed it down to this line:

if (o==window || o==window.docum ent)

Apparently, it doesn't like to compare strings to the
window object. This simple test case fails:

var x = "test";
alert(x==window );

That shouldn't fail with an error, should it?
Yes it may throw an exception. The test - x == window -, where x is a
string, is evaluated as the equivalent of - x == ToPrimitive(win dow) -,
and the internal ToPrimative function calls the object's
[[DefalutValue]] method, which is required to throw an exception when
the object does not implement either - toString - or - valueOf. So
probably the window object does not support these two methods. As the
ECMAScript global object the window is not required to implement (or
inherit) either method.
Comparing an <OPTION> object to the window object
crashes the browser completely.
A crash would be a bug.
Unless someone can justify why a browser should generate
an error when comparing an arbitrary object to the window
object,
It is comparing a string with the window object that is throwing
exceptions, and that is allowed.
I'll consider it a bug in Mac browsers and ignore
it :)


Why wasn't I surprised to read that? We should all be familiar with your
approach to problem solving by now.

Richard.
Jul 23 '05 #13
Richard Cornford wrote:
Yes it may throw an exception. The test - x == window -, where x is a
string, is evaluated as the equivalent of - x == ToPrimitive(win dow)
-, and the internal ToPrimative function calls the object's
[[DefalutValue]] method, which is required to throw an exception when
the object does not implement either - toString - or - valueOf.


So how would you suggest testing whether an object is the window object,
without knowing anything about the object?

I tried
if (typeof(o)=="ob ject" && (o==window || o==window.docum ent)

And that crashed the browser as well.
I'll consider it a bug in Mac browsers and ignore
it :)

Why wasn't I surprised to read that? We should all be familiar with
your approach to problem solving by now.


Oh, blow it out your ass, Richard. You and John Stockton can go have an Anal
Retentive Asshole party for all I care.

My statement was perfectly valid... _UNLESS SOMEONE CAN JUSTIFY WHY A
BROWSER SHOULD GENERATE AN ERROR_ then I'll consider it a bug. I don't just
blindly treat things as browser bugs and ignore them.

I've never seen such behavior in any other browsers, and Mac browsers are
notoriously bad (IMO) so when an error only occurs on mac browsers, I have
to question whether it's a browser quirk.

--
Matt Kruse
http://www.JavascriptToolbox.com
Jul 23 '05 #14
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.

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

etc. etc. etc.

Is there a utility that lets you do this?
Yes.
Also, is there any particular reason why a function wouldn't be able to
see a certain variable?
You are talking about object properties, not plain variables:
I'm calling javascript with the form:

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

<form name="form">
That `form' element lacks an `action' attribute to be Valid HTML.

<http://validator.w3.or g/>
<a href="javascrip t:download_subm it()">
<img src="...." ...>
</a>
You should refrain from submitting forms only by means of client-side
scripting, and you should definitely refrain from using proprietary
`javascript:' URIs in favor of well-standardized event handlers. It
is also recommended not to put whitespace after the start tag and/or
before the end tag of the `a' element, see the latest HTML 4 Specification.
<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 do not see a control named `foldercheckbox ' within your form (which could
be one of the reasons why this fails; it should yield a script error then,
possibly not displayed by default), but I do see proprietary references in
your code. In case there is a form control with that name, use

this.form.eleme nts['foldercheckbox '].value = this.value;

and in your function use

document.forms['form'].elements['foldercheckbox '].value

or rather use an `input' element and pass a reference on `submit' event:

function download_submit (f)
{
... f.elements['foldercheckbox '].value ...
// return true to submit, false to cancel submit
}

<form action="..." onsubmit="retur n download_submit (this);">
...
<input type="checkbox" name="filecheck box" value="myval"
onclick="this.f orm.elements['foldercheckbox '].value
= this.value;">
...
<input type="submit" ...>
<!-- or, with images -->
<input type="image" src="..." alt="..." ...>
</form>

This allows the form to be submitted even if client-side script support is
not available.

Keep in mind that

,-<http://www.w3.org/TR/DOM-Level-2-Events/events.html#Eve nts-eventgroupings-htmlevents-h3>
| [...]
| The change event occurs when a control loses the input focus
| and its value has been modified since gaining focus.

and that `value' does not specify the state of a checkbox but `checked'
does.
I'd like to dump out the document to see exactly *what*
the javascript function is seeing...


You may want to try my ObjectInspector embedded in a frame or an iframe:

<http://pointedears.de/objinsp>

(with parent.frames[...].document or parent.document ) or getObjInfo() from

<http://pointedears.de/scripts/test/debug.js>

The latter does not (yet?) provide automated recursive retrieval, though.
HTH

PointedEars
Jul 23 '05 #15

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
5300
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
3430
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
7348
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
1126
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
3540
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
9706
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
9579
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10575
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
10319
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
10076
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7616
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
5520
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
5651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4297
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.