473,387 Members | 1,864 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Fetching properties from a dynamically generated input element

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
2 2522
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Dave Nouwens | last post by:
Hi All, Please accept my appologies in advance for what I expect will be a reasonably simple question. I have an html form (which is generated in php) which contains a number of rows (one row...
1
by: Peter Kirk | last post by:
Hi there I have a form which submits a list of data to a web-application (which then saves to a database). The list consists of four input fields per row. Eg....
6
by: Luke Dalessandro | last post by:
I'm not sure if this is the correct forum for platform specific (Mozilla/Firefox) javascript problems, so just shout and point me to the correct newsgroup if I'm being bad. Here's the deal... ...
6
by: bradb | last post by:
Hello, I have a textbox with an empty span element (place holder) next to it. When the user adds some text to the text box, I create a checkbox in the empty span element. When I create the...
2
by: Sethos | last post by:
I am sure that this has been covered, hashed, and rehashed, but a search on the group did not produce the answer, so forgive me if this seems like a "newbie" type question... Besically, I have a...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
1
by: vega80 | last post by:
Hi. I have a problem with assigning an onkeypress-function to dynamically created input-boxes.I want to put the content of an input-field into a tag-list when the user hits enter. This works...
1
by: sarafraz | last post by:
I want to process the XML File and display it in the browser(IE). I have the written code which accepts the XML file as input,parses it and displays it in IE with proper indentation. To achieve...
9
by: student4lifer | last post by:
Hello, could someone show me how to make sticky form with dynamically generated form element? for example, if one likes to make the dynamically generated check box (and its name) 'sticky' that...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.