By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,205 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Fetching properties from a dynamically generated input element

P: n/a
I'm dynamically creating several form input elements:

mValue = integer constant;
for(var j = 0; j < mValue; j++) {
target = "imgCn"+ j;
eName = "myFile"; eName = eName+jj;
document.getElementById(target).innerHTML =
"<input type = 'file' name="+eName+" value=''>text";
}

These are created at placemarks in the HTML page, e.g.,
<span id = 'imgCn0'></span>
<span id = 'imgCn1'></span>
etc.

When I submit the form to a Perl script I want to verify that the
file-selection input elements are populated. I use a js validation script
and I've tried:

isValue = document.getElementById('imgCn0').value;
and
isValue = document.form2.elements["imgCn1"].value;

These produce 'undefined' for isValue.

How do I test dynamically-created input elements for validity?
--
Ed Jay (remove 'M' to respond by email)
Apr 10 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Apr 10, 11:57 am, Ed Jay <e...@aes-intl.comwrote:
I'm dynamically creating several form input elements:

mValue = integer constant;
for(var j = 0; j < mValue; j++) {
target = "imgCn"+ j;
eName = "myFile"; eName = eName+jj;
document.getElementById(target).innerHTML =
"<input type = 'file' name="+eName+" value=''>text";

}

These are created at placemarks in the HTML page, e.g.,
<span id = 'imgCn0'></span>
<span id = 'imgCn1'></span>
etc.

When I submit the form to a Perl script I want to verify that the
file-selection input elements are populated. I use a js validation script
and I've tried:

isValue = document.getElementById('imgCn0').value;
and
isValue = document.form2.elements["imgCn1"].value;

These produce 'undefined' for isValue.

How do I test dynamically-created input elements for validity?
--
Ed Jay (remove 'M' to respond by email)
is this only happening on type="file" input elements, or all input
elements? (or are you only using type="file" elements?)

if it's only the type="file" elements, the browser might be blocking
the javascript from accessing that info. (i know browsers block
javascript from setting the value of a type="file", but i'm not sure
about getting the value).

if it's all input elements, you might need to scrap using the
innerHTML property and instead use document.createElement().

Apr 10 '07 #2

P: n/a
brunascle scribed:
>On Apr 10, 11:57 am, Ed Jay <e...@aes-intl.comwrote:
>I'm dynamically creating several form input elements:

mValue = integer constant;
for(var j = 0; j < mValue; j++) {
target = "imgCn"+ j;
eName = "myFile"; eName = eName+jj;
document.getElementById(target).innerHTML =
"<input type = 'file' name="+eName+" value=''>text";

}

These are created at placemarks in the HTML page, e.g.,
<span id = 'imgCn0'></span>
<span id = 'imgCn1'></span>
etc.

When I submit the form to a Perl script I want to verify that the
file-selection input elements are populated. I use a js validation script
and I've tried:

isValue = document.getElementById('imgCn0').value;
and
isValue = document.form2.elements["imgCn1"].value;

These produce 'undefined' for isValue.

How do I test dynamically-created input elements for validity?
--
Ed Jay (remove 'M' to respond by email)

is this only happening on type="file" input elements, or all input
elements? (or are you only using type="file" elements?)
I'm using a mix of types, but I've only had occasion to test the file
elements.
>
if it's only the type="file" elements, the browser might be blocking
the javascript from accessing that info. (i know browsers block
javascript from setting the value of a type="file", but i'm not sure
about getting the value).

if it's all input elements, you might need to scrap using the
innerHTML property and instead use document.createElement().
--
Ed Jay (remove 'M' to respond by email)
Apr 10 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.