/    Sign up×
Community /Pin to ProfileBookmark

Dynamically Fill DIV during Validation

Hi,

I am kind of a newbie to web development. I am trying to create a web form for a class I am teaching. The idea is to have the students fill in the webform and, when they click submit, it will validate the contents to make sure all the questions were answered.

I have most of it working except the piece whereby I display the list of fields they did not fill in.

To do this, I created a simple <DIV> in the HTML just above the form definition. The div is blank. Here’s the HTML for that…

[FONT=”Courier New”]<div id=”divErrors”></div>[/FONT]

The idea is that when the user clicks submit, I want to first clear out the contents of the div as follows:

[FONT=”Courier New”] document.divErrors.innerHTML=””;[/FONT]

and once I have done that, I test the contents of the fields and append them to the innterHTML as follows:

[FONT=”Courier New”] if(frmMain.name.value==””){
if(!llError){
document.divErrors.innerHTML = lcMsg;
llError = true;
}
document.divErrors.innerHTML += “<LI>Your name.</LI>”;
}
[/FONT]

Here’s my problem. When the code gets to document.divErrors it tells that the element has no properties.

I have googled this but I cannot seem to figure out why this is happening or how to fix it. The <DIV> is definitely within the body of the HTML.

I am developing in FireFox but this will have to run in IE as well.

Any assistance would be greatly appreciated.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangSep 03.2007 — Incorrect referencing of element, use: document.getElementById('divErrors').innerHTML
Copy linkTweet thisAlerts:
@bazianmauthorSep 04.2007 — That was it! Thanks a million!
×

Success!

Help @bazianm 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 6.26,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ,
analytics: Fullres
});

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: @Marika,
tipped: article
amount: 1000 SATS,

tipper: @hatem774,
tipped: article
amount: 1 SATS,

tipper: @nearjob,
tipped: article
amount: 1000 SATS,
)...