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; &nbs p; Type: " + $type +
"<br>");
newwin.document .write(" & nbsp; &nbs p; Curren t Value: "
+ $value + "<br>");
newwin.document .write(" & nbsp; &nbs p; Checked : " +
$checked + "<br>");
newwin.document .write(" & nbsp; &nbs p; Checke d by
default: " + $defaultchecked + "<br>");
newwin.document .write(" & nbsp; &nbs p; Disable d: " +
$disabled + "<br>");
newwin.document .write(" & nbsp; &nbs p; Selecte dIndex: "
+ $selectedindex + "<br>");
newwin.document .write(" & nbsp; &nbs p; 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>