Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Browsers / Internet Explorer / February 2005



Tip: Looking for answers? Try searching our database.

Dynamically Created Elements Not Posting

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
news@fastwave.net - 17 Feb 2005 00:48 GMT
I'm using JavaScript and  DOM methods to create a dynamically growing
table within a form contained in an *.asp page.

The first row is fixed using static table elements. When you click an
'ADD' button to add subsequent rows, the first (static) row is copied
using the [object].cloneNode() method. and the element names are
changed using the [element].setAttribute() method. This all works
fine, and I have verified that the dynamic names are there.

Clicking the form 'Submit' button envokes a confirmation *.asp page
using the following HTML tag modifier:

    action="Confirmation.asp"

The confirmation page shows the static table element values but not
the dynamically created element values.

Can someone explain to me how to pass / post the dynamically created
elements values to the confirmation page by 'name'? I thought that
since the names exist for the new row elements, they would be passed
just like the static named elements, but it doesn't appear to work
that way.

Thanks!
Bob Barrows [MVP] - 18 Feb 2005 15:19 GMT
> I'm using JavaScript and  DOM methods to create a dynamically growing
> table within a form contained in an *.asp page.
[quoted text clipped - 20 lines]
>
> Thanks!

This seems to work for me:

<%
if len(Request.Form("text1")) > 0 then
for each key in Request.Form
 Response.Write key & ": " & Request.Form(key) & "<BR>"
next
Response.End
end if
%>
<HTML>
<HEAD>
<SCRIPT LANGUAGE=javascript>
function AddBox() {
var tbl = document.getElementById("tbl");
if (tbl.rows.length<3)
{
 var oRow=tbl.insertRow()
 var oCell=oRow.insertCell()
 obj=document.getElementById("text1").cloneNode();
 obj.name="text2";
 obj.id="text2";
 oCell.appendChild(obj)
}
}
</SCRIPT>
</HEAD>
<BODY>
<form id="frm" method="post"
onsubmit="return (document.getElementById('text1').value != '');">
<table id="tbl" border="0">
<tr>
<td>
 <input id="text1" name="text1" type="text">
</td>
</tr>
</table>
<BR><button onclick="AddBox();" id=button1 >Add Row</button>
<INPUT type="submit" value="Submit" id=submit1 >
</form>
</BODY>
</HTML>

Bob Barrows
Signature

Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.

news@fastwave.net - 20 Feb 2005 01:06 GMT
Hi, Bob.

Thanks for responding!

I got your example to work and have a couple of questions. I'm just
learning this stuff, so my questions will, most likely, sound naive.

  1. The server-side code at the top of your example...what language
is it?

  2. The server-side code uses the term 'key'. Is this a term used to
describe the variables or variable names passed using the 'post'
method of a form?

  3. Is the term 'key' specific to the language code in question #1,
or can it be accessed by another language? Is it part of the DOM?

  4. I'm trying to keep all the code in JavaScript, and I cannot find
any reference to the term 'key' in the book I am learning from. Is
there a JavaScript equivalence for 'key' (or, an alternate way to do
this in JavaScript)?

Many thanks!

Kim

>This seems to work for me:
>
[quoted text clipped - 40 lines]
>
>Bob Barrows
Bob Barrows [MVP] - 20 Feb 2005 15:38 GMT
> Hi, Bob.
>
[quoted text clipped - 5 lines]
>   1. The server-side code at the top of your example...what language
> is it?

vbscript

>   2. The server-side code uses the term 'key'. Is this a term used to
> describe the variables or variable names passed using the 'post'
> method of a form?

No. It's a variable. SP provides a Request object with various properties
and collections containing data supplied by the page that issued the
request. One of the collections is called Form. Another collection is called
Querystring. Depending on the method used to submit your form, one of these
collections will contain the data from your form elements. if you use
"post", the the Form collection contains the data. If you use "get", then
the querystring collection contains the data.

Each collection has a key (the same way any collection in COM has a key)
that identifies the data contained in each element of the collection. With
vbscript, a collection can be iterated through by the key using a "for each"
statement.

>   3. Is the term 'key' specific to the language code

No. it's simply the name I chose to use for the iteration variable. I could
have used:
for each i in Request.Form

> in question #1,

No. All COM collections are keyed, and any language that can reference a COM
collection can use the key.

> Is it part of the DOM?

The DOM also has collections that can be iterated through using a key. The
DOM is not available in server-side code - only client-side.

>   4. I'm trying to keep all the code in JavaScript, and I cannot find
> any reference to the term 'key' in the book I am learning from. Is
> there a JavaScript equivalence for 'key' (or, an alternate way to do
> this in JavaScript)?

Yes, you can use an Enumerator object to iterate through the collection:

<%@ Language=JavaScript %>
<%
var e = New Enumerator(Request.Form")
if (Request.Form.Count > 0)
{
var e = new Enumerator(Request.Form)
for (; !e.atEnd(); e.moveNext())
{
 Response.Write (e.item() + ": " +
       Request.Form(e.item()).Item + "<BR>")
}
Response.End
}
%>

Bob Barrows
Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Bob Barrows [MVP] - 20 Feb 2005 16:05 GMT
> No. It's a variable. SP provides a Request object with various

Hmm, what happened to the "A"? It should say:
"ASP provides ... "

Bob Barrows
Signature

Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.