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="JavaScript">
<!--
function form_dump($form_name){
$form = document.forms[$form_name];
var newwin =
window.open("","formdumpwin","menubar,scrollbars,r esizable,width=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("Onsubmit: " + $form.onSubmit + "<p><hr>");
newwin.document.write("Parameters: <br>");
for(var i=0;i<$form.elements.length; i++){
//Element information and general attributes
$element = $form.elements[i];
$type = $element.type;
$checked = $element.checked;
$defaultchecked = $element.defaultChecked;
$disabled = $element.disabled;
$defaultvalue = $element.defaultValue;
$belongsto = $element.form;
$name = $element.name;
$value = $element.value;
$selectedindex = $element.selectedIndex;
$length = $element.length;
//Event binders
$onclick= $element.onclick;
$onmouseover = $element.onmouseover;
if($disabled == "true"){
newwin.document.write("<div style='color: grey'>");
}
newwin.document.write("Parameter name: " + $form.elements[i].name +
"<br>");
newwin.document.write(" &nb sp;Type: " + $type +
"<br>");
newwin.document.write(" &nb sp;Current Value: "
+ $value + "<br>");
newwin.document.write(" &nb sp;Checked: " +
$checked + "<br>");
newwin.document.write(" &nb sp;Checked by
default: " + $defaultchecked + "<br>");
newwin.document.write(" &nb sp;Disabled: " +
$disabled + "<br>");
newwin.document.write(" &nb sp;SelectedIndex: "
+ $selectedindex + "<br>");
newwin.document.write(" &nb sp;Length: " +
$length + "<br>");
if($disabled == "true"){
newwin.document.write("</div>");
}
}
newwin.document.close();
}
function choose_form_dump(){
var newwin =
window.open("","chooseformdump","menubar,scrollbar s,resizable,width=600,height=400");
newwin.document.write("<b>Available 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_dump('"+
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="choose_form_dump();return false;">
<input type="text" name="test" value="whatever">
<input type="text" name="hideme" value="invisible" disabled>
<input type="submit" name="submit">
</form>
</body>
</html>