/    Sign up×
Community /Pin to ProfileBookmark

Folks

Has anyone got a quick function to add the values from text fields?

I want to do it as I go so intend to use onblur to activate the function and post the running total back to total field.

Any clues?

Cheers

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@CharlesAug 19.2003 — [font=georgia]Don't actually release this on the internet - JavaScript is way too iffy - but for demonstration purposes:[/font]

[font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<title>Example</title>

<style type="text/css">

<!--

input {display:block}

-->

</style>

<form action="">

<div>

<input type="text" name="one" onchange="this.form.total.value = Number(this.value) + Number(this.form.two.value)">

<input type="text" name="two" onchange="this.form.total.value = Number(this.value) + Number(this.form.one.value)">

<hr>

<input type="text" name="total">

</div>

</form>[/font]
Copy linkTweet thisAlerts:
@blokeauthorAug 19.2003 — [i]Originally posted by Charles [/i]

[B][font=georgia]Don't actually release this on the internet - JavaScript is way too iffy - but for demonstration purposes:[/font]

[/QUOTE]


Do you have an alternative to javascript then?
Copy linkTweet thisAlerts:
@CharlesAug 19.2003 — [font=georgia]Submit the form to a server side script which returns the form but updated.[/font]
Copy linkTweet thisAlerts:
@blokeauthorAug 19.2003 — Yeah, thought as much. Wanted to avoid that hence the javascript.

It's only for use on an intranet anyway so I know javascript will be supported for all of the users.

Cheers for your help.
Copy linkTweet thisAlerts:
@Khalid_AliAug 19.2003 — [i]Originally posted by Charles [/i]

[B][font=georgia]Submit the form to a server side script which returns the form but updated.[/font] [/B][/QUOTE]


Cmon charles..that will be killing the bandwidth..if some one has validations as in this case where you have to validate form fields on every onclick or onblur or on change..god just imagine the activity that will generate towards and from the server..

But hey I am a JavaScript lover so what can I say..:-)? ? ?
Copy linkTweet thisAlerts:
@blokeauthorAug 19.2003 — Managed it with this:

<SCRIPT LANGUAGE=javascript>

var total = 0;

function addVal(obj)

{

//parseInt FUNCTION CONVERTS DATA INTO INTEGERS

total = parseInt(total) + parseInt(obj.value);

document.purchase.totalvalue.value = total;

}

</script>

Then:

<td>&pound;&nbsp;<input type="text" name="total" size="10" maxlength="20" class="contentdetailnew" onBlur="addVal(this);"></td>

And:

<td colspan=2>&pound;&nbsp;<input type="text" name="totalvalue" size="30" maxlength="30" class="contentdetailnew" readonly></td>


Hunky Dory!
×

Success!

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