/    Sign up×
Community /Pin to ProfileBookmark

how to access the textboxe array through javascript

Hi All,
i am new to this forum,
My Question is how can i access the textboxes array through javascript for form validation
i am mentioning the example code so that you all can better understand

<form name=”xyz” onSubmit=”return Validate(this)” method=”any”>
<input type=”text” name=”agentname[]” />
<input type=”text” name=”agentname[]” />
<input type=”text” name=”agentname[]” />
<input type=”text” name=”agentname[]” />

<!– Other Form Controls –>

<input type=”submit” />

</form>

now i have to access all the textboxes to validate their data ..
i hope you can understand my problem
Thanks

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisOct 26.2007 — When you use the same name for form elements, an array is created. Your form has an array of "agentname[]" elements:
<i>
</i>document.forms["xyz"]["agentname[]"][0]
will get the first one.
Copy linkTweet thisAlerts:
@samliewOct 27.2007 — You could use a loop to go through each of the textboxes.

for(i=0;i&lt;document.forms["xyz"]["agentname[]"].length;i++) {
if(document.forms["xyz"]["agentname[]"][i].value=="") { alert('Please fill in a value for textbox '+i); }
}
Copy linkTweet thisAlerts:
@shoaibahmedkhanauthorOct 30.2007 — [COLOR="DarkGreen"]thanks for both of you, i have found your replies very helpful, once again i appreciate your kindness.[/COLOR]
Copy linkTweet thisAlerts:
@samliewOct 31.2007 — Glad we could help.
×

Success!

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