/    Sign up×
Community /Pin to ProfileBookmark

I have a page that allows you to input data into two input text fields. I then need to loop through the amount of input text boxes on the page and add the values together. So if someone enters 3 and 1, I need a message box that returns 4 in addition to adding the informaiton to the cookie. It’s part of a shopping cart code I previously had working but I did somehting and now it can’t recognize the form to loop through it. Does it matter where a form is defined?

The source can be seen at…
[url]https://webspace.utexas.edu/haunsc/testing.htm[/url]

Unfortunately none of the images or the menu graphics show up…hopefully someone can help with the Javascript and form definition.

I think it may have to do with where I define the form, but I don’t know…

All of my hair is on the ground form (bad pun?) pulling at it!

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@steelersfan88Mar 19.2004 — This might be IE only, but try:[code=php]<script type="text/javascript">

function getSum() {
var theSum = new Number()
for(var i=0;i<document.myForm.elements.length;i++) {
if(document.myForm.elements[i].type == "text") {
theSum += new Number(document.myForm.elements[i].value)
}
}
alert(theSum)
}

</script>

<form name="myForm">
Number 1: <input type="text" id="num1"><BR>
Number 2: <input type="text" id="num2"><BR>
Number 3: <input type="text" id="num3"><BR>
Number 4: <input type="text" id="anothernum4"><BR>
<input type="button" value="Calc Sum" onclick="getSum()">
</form>[/code]
Don't ask me about cookies, I am totally against using them.

You said it yourself, let me add the word very to it, very bad...
×

Success!

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