I have created a form in a iframe (using Walter Zorn’s wz_tooltip.js) and I want to use javascript to validate the contents before posting. I’m not sure what parameter in the DOM to use to retrieve the data. When not in an iframe I can use (document.testit1.form1.value) and data is returned properly. When I attempt this (document.testit2.form2.value) when the form is in an iframe I receive the error
document.testit2.form2 is undefined
document.write(document.testit2.form2.value);
The link for the sample code is [url]http://www.schuckman.com/misc/testform/testform.html
Follows is sample code to demonstrate the problem
Any help will be appreciated.
[CODE]<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN” “http://www.w3.org/TR/html4/loose.dtd”>
<html>
<head>
<title>Test form</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<script type=”text/javascript” language=”JavaScript”>
function displayData1() {
document.write(document.testit1.form1.value);
}
function displayData2() {
document.write(document.testit2.form2.value);
}
</script>
</head>
<body>
<script type=”text/javascript” src=”wz_tooltip.js”></script>
<script type=”text/javascript” src=”tip_centerwindow.js”></script>
<p>This part works properly</p>
<form name=”testit1″ onSubmit=”return displayData1()”>
Form Field 1: <input type=”text” name=”form1″ value=”Jumper1″ size=”10″ maxlength=”10″><br>
<input type=”submit” value=”Post Data 1″>
</form>
<p>This part fails with the error “document.testit2.form2 is undefined – document.write(document.testit2.form2.value);” after “Post Data 2” is clicked. </p>
<p><a href=”#null” onclick=”TagToTip(‘marker1’, CENTERWINDOW, true, CENTERALWAYS, true, TITLE, ‘Form Test’)”>Click Here</a> to display form, then click Post Data 2.</p>
<div id=”marker1″>
<form name=”testit2″ onSubmit=”return displayData2()”>
Form Field 2: <input type=”text” name=”form2″ value=”Jumper2″ size=”10″ maxlength=”10″><br>
<input type=”submit” value=”Post Data 2″>
</form>
</div>
</body>
</html>