/    Sign up×
Community /Pin to ProfileBookmark

array of textfields

I have written this code and it executes well but I would like to instead of using an array of multiple textfields write an array that will allow me to add additional textfields but not have to add a new array element. Can anyone help me with writing this array?

[CODE]
<script language=”JavaScript”>
function calculate(what) {

var text = new Array(4)
text[0] = document.chmod.textField1
text[1] = document.chmod.textField2
text[2] = document.chmod.textField3
text[3] = document.chmod.textField4
text[4] = document.chmod.textField5

var boxes = document.chmod.box;
var a=0;
var b=0;

for (i = 0; i < boxes.length; i++)
{
if (boxes[i].checked == true)
{
a +=(text[i].value*1)
} else if (boxes[i].checked == false) {
b +=(text[i].value*1)
}
}
document.chmod.Matching_Funds.value=a
document.chmod.Other_Funds.value=b
}
</script>

<input type=”text” size=”12″ name=”textField1″ onBlur=”calculate(this.form)”></td>
[CODE]

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Apr 08.2005 — There are a bunch of ways of doing it, this is one way...

<i>
</i>numBoxes = 15;
var text = new Array(numBoxes);
for(i=0;i&lt;numBoxes;i++){
text[i] = document.chmod["textField" + (i+1)];
}


Another way is loop through the form array and search for the text boxes.

Eric
Copy linkTweet thisAlerts:
@broken__barrierauthorApr 08.2005 — so if i loop through the form searching for text boxes will my check boxes still register???
Copy linkTweet thisAlerts:
@broken__barrierauthorApr 08.2005 — thank you eric for you help... when i add in the snippet it works but it no longer calculates
×

Success!

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