/    Sign up×
Community /Pin to ProfileBookmark

check dynamic input

HI,

I have a form that is dynamically generated. I have no problem with the form that works fine, but now I want to check if a user has filled out the information. A small piece of code is here when the form is made.

while (i<something)
{
heightInput.setAttribute(“id”,””);
heightInput.id=”itemHeight_“+i;
heightInput.setAttribute(“name”,””);
heightInput.name=”itemHeight_
“+i;
i++;
}
so now I have names for my input fields of itemHeight_0, itemHeight_1 and so on.

I now want to check these when they are submitted, I have tried this below but of course it is not seeing itemName_+a; as the fieldname. I could pull all the elements by tag and then go through the array checking these, but I have other text boxes on the form that that would be difficult. Anyone got any ideas? I don’t know how many of these text boxes will be generated so I need an automated approach.

a=0;
while(a<numberItems)
{

//the form has already been got by element id and stored as theForm.
var setName=’itemName_’+a;
alert(setName);

if (theForm.setName.value==”)
{
alert(‘name not set’);
hasError=true;
sError += ” Please xxx.n”;
}
a++;
} // while

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@vwphillipsDec 16.2008 — try using this to generate the form field

[CODE]function zxcFormField(zxctag,zxcnme,zxctype){
var zxcel;
try {
zxcel=document.createElement('<'+zxctag+(zxctype?' type='+zxctype:'')+' name='+zxcnme+' >');
}
catch (zxce){
zxcel=document.createElement(zxctag);
if (zxctype) zxcel.type=zxctype;
zxcel.name=zxcnme;
}
return zxcel;
}
[/CODE]
×

Success!

Help @steveclondon 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.8,
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,
)...