/    Sign up×
Community /Pin to ProfileBookmark

Problem with right justify.

I am trying the interest example in the O’Riley JavaScript book and am experimenting with right justify since all input and output is numeric. The input is justified but not the output.

“`
[code]<style> /* This is a CSS style sheet: it adds style to the program output */
input { text-align:right;
type:”number”} // Since all data is numeric, right justify everything.
.output { font-weight: bold; /* Calculated values in bold */
text-align: right; } /* Same as input */
#payment { text-decoration: underline; } /* For element with id=”payment” */
#graph { border: solid black 1px; } /* Chart has simple border */
th, td {vertical-align: top; } /* Don’t center table cells */
</style>
————————————-
<table>
<tr><th>Enter Loan Data:</th>
<td></td>
<th>Loan Balance Cumulative Equity, and Interest Payments</th></tr>
<tr><td>Amount of the loan ($):</td>
<td><input id=”amount” onchange=”calculate();”></td>
<td rowspan=8>
<canvas id=”graph” width=”400″ height=”250″></canvas></td></tr>
<tr><td>Annual Interest (%):</td>
<td><input id=”apr” onchange=”calculate();”></td></tr>
<tr><td>Repayment period (years):</td>
<td><input id=”years” onchange=”calculate();”></td></tr>
<tr><td>Zipcode (to find lenders):</td>
<td><input id=”zipcode” onchange=”calculate();”></td></tr>
<tr><th>Approximate Payments:</th>
<td><button onclick=”calculate();”>Calculate</button></td><tr>
<tr><td>Monthly payment:</td>
<td>$<span class=”output” id=”payment”></span></td><tr>
<tr><td>Total payment:</td>
<td>$<span class=”output” id=”total”></span></td><tr>
<tr><td>Total interest:</td>
<td>$<span class=”output” id=”totalinterest”></span></td><tr>
<tr><th>Sponsors:</th><td colspan=2>
Apply for your loan with one of these fine lenders:
<div id=”lenders”></div></td></tr>
</table>[/code]
“`

This is what I have so far: https://wjporter.com/files/interest.html
TIA

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@tracknutJul 22.2019 — You've an illegal comment style in your css ("// since alll data....") which is causing trouble with your .output style. Change that comment to /* .... */ like the others
Copy linkTweet thisAlerts:
@wbportauthorJul 23.2019 — Thanks for looking at it. I changed it to
``<i>
</i>&lt;style&gt; /* This is a CSS style sheet: it adds style to the program output */
input { text-align: right;
type:"number"} /* Since all data is numeric, right justify everything. */
.output { font-weight: bold; /* Calculated values in bold */
text-align: right; } /* Same as input */
#payment { text-decoration: underline; } /* For element with id="payment" */
#graph { border: solid black 1px; } /* Chart has simple border */
th, td {vertical-align: top; } /* Don't center table cells */
&lt;/style&gt;<i>
</i>
``

but it didn't seem to help,
Copy linkTweet thisAlerts:
@tracknutJul 23.2019 — Sorry I just noticed, you've got the values in a <span>, which will push them to the left. You'd probably need to give the span a "display:block", or better, get rid of the span and just put the text in the <td> with no tags around it:

<td id="payment" class="output"></td><tr>
Copy linkTweet thisAlerts:
@wbportauthorJul 23.2019 — I am trying to copy their example (https://resources.oreilly.com/examples/9780596805531/blob/master/examples/01.01.loancalc.html) but feel I will learn faster if I experiment a little. It now right justifies the answers but takes an extra line each.

My page based on the same book **3rd** (current is 6th) edition is https://wjporter.com/money/mortgage.htm and I have added a lot to it, starting with breaking loan duration into years and months. It was all forms and tables with no CSS.
×

Success!

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