/    Sign up×
Community /Pin to ProfileBookmark

Dividing a number, then display that result in a form field

The form I’d like to modify populates this field (balance amount) upon the page appearing:

“`
<div class=”col-md-10″>
<input type=”text” readonly=”true” class=”form-control input-md” type=”number” placeholder=”00″ value=”{{balance}}”>
</div>
“`

I’d like to divide that balance amount by 2, and have that result display it’s own seperate form field.
Any help with this is appreciated.

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@JMRKEROct 19.2021 — To begin with, you will need to create an element to hold the result.

Then you need to create a variable to hold the contents of the input.

Using that variable, divide by 2 and limit precision if necessary

Finally, place the results of the divide into the element that you wish to display.

Give it a shot.
Copy linkTweet thisAlerts:
@chrisjchrisjauthorOct 19.2021 — Thanks for your reply.

Regarding, "you will need to create an element to hold the result", you mean creating another Form Field, correct?"

In regard to "you need to create a variable to hold the contents of the input", can you be more specific?

What does this mean: "and limit precision if necessary"?

"place the results of the divide into the element", can you give me an example?
Copy linkTweet thisAlerts:
@NogDogOct 19.2021 — > @chrisjchrisj#1638318 What does this mean: "and limit precision if necessary"?

Depending on what the starting number is, dividing it by 2 may end up with a value with some number of digits after the decimal point. You may want to round it or otherwise truncate it to whatever precision you want to use.
Copy linkTweet thisAlerts:
@JMRKEROct 19.2021 — @chrisjchrisj#1638318

Yes, create another field to show the results of your calculations.

A variable is necessary to hold the the calculation results until displayed.

Can't do your homework, but we can comment on your attempts at the solution.

Expand the code of your first post.
×

Success!

Help @chrisjchrisj 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 4.26,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...