faqts : Computers : Programming : Languages : JavaScript : DHTML

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

35 of 43 people (81%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

How do I submit a form that is inside of a layer tag (by clicking a graphic, not a submit button)

Oct 24th, 2000 15:44
Tim Powell, Frank Garamy,


A trick to working with layers is knowing how to reference the objects 
inside them. Netscape treats each layer as a new document. To reference 
a form named Frm in a layer named Lyr, you use 
document.Lyr.document.Frm. In the following code, you can submit the 
form using either the image link (using JavaScript) or the image submit 
button inside the form (no JavaScript required).
<a href="javascript:document.Lyr.document.Frm.submit()"><img src=""></a>
	<layer name="Lyr">
	<form name="Frm" method="get">
	<input type="text" name="txtfield">
	<input type="image" src=""> <!-- Submit button -->
	</form>
	</layer>
Notice that the layer includes the form tag. Since Netscape treats each 
new layer as a new document, forms cannot be continued across layers. 
For those that are interested in cross browser compatibility, Netscape 
treats a positioned DIV identically to a layer, so the layer tags could 
be replaced with <div id="Lyr" style="position: absolute"> in the above 
example. However, you'd still need to reference the form differently 
than in IE.