SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: submit dynamicly created Form
-
Apr 27, 2001, 21:33 #1
- Join Date
- Apr 2001
- Location
- Ottawa
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hi,
I am having a problem referencing just created form.
The: document.bForm.submit(); works fine if the
form is created as a fixed HTML, but when
created dynamically, it does not work.
No errors, just nothing.
This line:
alert("name:" + document.bForm.name);
will not do anything either?
So the questions is:
HOW do you reference objects craeted on the fly?
Thanks,
Zenon
======== code of my test ========
<html>
<head>
<title>T1</title>
<script language='javascript'>
function sendBuffer() {
sContent='<form name="bForm" action "phpserver.php">First Name <input type="text" name="f1" value="John"> <br> Last Name <input type="text" name="f2" value="Doe"><br></form>';
alert(sContent);
lyrHTML = document["formLyr"].document;
lyrHTML.open();
lyrHTML.write(sContent);
lyrHTML.close();
//alert("name:" + document.bForm.name);
document.bForm.submit();
// ............the two lines above do not work
}
</script>
</head>
<body>
<H2>Dynamic Form test for Netscape 4.*</H2>
<a href="javascript:sendBuffer()">Create and submit the form</a>
<div id="formLyr" style="position:absolute; width:254px; height:76px; z-index:1; left: 295px; top: 83px;visibility: visible;">
</div>
</body>
</html>
-
Apr 30, 2001, 12:43 #2
- Join Date
- Apr 2001
- Location
- UK
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You have a few errors in your code which would be worth correcting. First you have written 'action "phpserver.php"' missing out the equals sign. This will of course cause problems when you try to submit the form.
Also you have remembered to treat the contents of the layer as a second document initially, but when you came to the following too lines you forgot:
alert("name:" + document.bForm.name);
document.bForm.submit();
They should be:
alert("name: " + document["formLyr"].document.bForm.name);
document["formLyr"].document.bForm.submit();
Finally, you have written 'href="java script:sendBuffer()"' in your anchor tag which has a space in the middle of javascript. It shouldn't be there.
Hope that helps.jonathan
-
Apr 30, 2001, 13:15 #3
- Join Date
- Apr 2001
- Location
- Ottawa
- Posts
- 3
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Thank You
Thank You, Jonathan.
I got this working.
Yes, in nn4 the layer must be on the path to the objects it contains. I discovered it the hard way.
That space in "java script" must be a ghost that got there during cut-and-paste (I think).
Thanks again.
Zenon
-
Apr 30, 2001, 13:30 #4
- Join Date
- Apr 2001
- Location
- UK
- Posts
- 18
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
You're welcome, glad to hear it works.
jonathan
Bookmarks