I am trying to write a script which returns a "Form Tree" for a page.
basically, you type the address of a page into a textbox, then hit a button to open that page and set a reference to it. you then hit another button to display the form tree in the form of nested unordered lists.
I am using 3 files currently (shown below):
1. The main form of the script
2. the code behind the scriptHTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Form Search</title> <script language="javascript" src="formtree.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form name="form1" method="post" action=""> <input type="text" name="txtURLtoCheck" id="URLtoCheck" value="formsearchtesting.htm" /> <input name="cmdSubmit" value="Open Window" type="button" onClick="open_win()" /> <input name="cmdGetTree" value="Get Form Tree" type="button" onClick="formtree()" /> </form> </body> </html>
3. A page with forms to test it out on:Code:// GLOBAL VARIABLES // var win = "" function open_win() { var url = document.forms[0].txtURLtoCheck.value; win = window.open(url); } function formtree() { /* * Display the Names of all the forms on the page * and all the elements thereof */ var id document.write("<form>Form Tree for " + win.document.title + "<br />"); documen document.write("<ul>"); for (i = 0; i < win.document.forms.length; i++) { document.write("<li>" + win.document.forms[i].name + "<ul>"); for (j = 0; j < win.document.forms[i].elements.length; j++) { id = "chk_" + i + "_" + j; document.write("<li>" + "<input type='checkbox' name='" + id + "' id='" + id + "'/>" + win.document.forms[i].elements[j].name + "</li>"); } document.write("</ul></li>"); } document.write( "</ul></form>" + "End of Form Tree"); }
As I said, it works in IE, but in Firefox it gives me an error saying that the variable "win" is not defined on line 23. This is after it displays the title of the test page.HTML Code:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Testing Forms</title> <script language="javascript" src="formtree.js"></script> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <hr /> <p>a form</p> <form name="frm1" method="post" action=""> <p>type something here <input name="txt_1" type="text" id="txt_1"> </p> <p> <input name="chkCheckBox" type="checkbox" id="chkCheckBox" /> checkbox</p> <p> <select name="cboName" id="cboName"> <option value="1">bob</option> <option value="2">sally</option> <option value="3">john</option> <option value="4">mike</option> <option value="5">kim</option> </select> </p> </form> <p>another form</p> <form name="form2" method="post" action="javascript:formtree()"> <p> <textarea name="txtArea" id="txtArea" style="width:20em;" rows="">type some text here</textarea> </p> <p> <input type="submit" name="cmdSubmit" id="cmdSubmit" value="Submit"> </p> </form> <hr /> <p> </p> </body> </html>
is the variable getting lost somewhere after it displays the title?
Any help with what is going on would be appreciated.
Thanks,
Aaron B. Davis


Reply With Quote
Bookmarks