/    Sign up×
Community /Pin to ProfileBookmark

Access Input values (createElement(‘input’)

I have a page where i add text boxs and such w/ the click of a button.
Example.

[code]
var tbl = document.getElementById(‘tblLines’);
var lastRow = tbl.rows.length;
var iteration = lastRow;
var row = tbl.insertRow(lastRow);

var cell0 = row.insertCell(0)

var cell1 = row.insertCell(1)
inputNode = document.createElement(‘input’);
inputNode.setAttribute(‘type’, ‘text’);
inputNode.setAttribute(‘name’, ‘txtNewShipQty_’ + iteration);
inputNode.setAttribute(‘size’, ‘8’);
inputNode.id = ‘Text10’;
cell1.appendChild(inputNode);
[/code]

Now the text box and all elements are created just fine and when i sumbit the page i can access the values of these elements w/ asp and write them into a database.

But the issue is when i need to say validate the elemets.

It seems that if i set the name like this

[code]
inputNode.setAttribute(‘name’, ‘txtNewShipQty_’ + iteration);
[/code]

Then i am unable to access this element w/ javascript again.
BUT
if i set the name ( and for what ever reason the id has to be the same for this to work, if i just set the name and do not set the id to the same name as the id then i will also get a error) like this

[code]
inputNode.name = ‘txtNewShipQty_’ + iteration;
inputNode.id = ‘txtNewShipQty_’ + iteration;
[/code]

When i say i get an error, i do not get an alert type error, i just get the yellow exlamation point icon in the status bar of the browser.

I just got this working but im looking for an explination on this.

Any ideas?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangFeb 14.2006 — [I]obj.setAttribute('name', 'foo')[/I] can cause accessibility problem, especially with IE.

Accessing the object with the elements array (document.forms['formName'].elements[0]) will work.

The warning is probably the undefined variable [I]inputNode[/I]
Copy linkTweet thisAlerts:
@lmf232sauthorFeb 14.2006 — well thanks for the info, ill go ahead and add that as a note so i dont make that mistake next time or spend for ever trying to figure out whats happening.

Thanks.
×

Success!

Help @lmf232s spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...