Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

write to page instead of to textbox - document.write not working

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
GB
I have a javascript calculator that calculates payments. users type their balance owed into a form, and then click on a "calculate" button which calls in the function below, and interest rate paymetn is calculated and shown in another textbox on the form.

the problem i'm having is this: Instead of showing the calculation in a textbox, i would like to show it as normal text on the page, not in a box.

i tried doing document.write, but that shows only the total, and all other info on the page dissapears.

Is there another way of doing this?

here's my code:

<script language='Javascript'>

function calcPayment(form)

{

var cardName = form.cardName.value;

var balance = form.balance.value;

balance = stripCharacter(balance,',');
balance = stripCharacter(balance,' ');


var rt = balance*0.03;

rt = rt * 100;

rt = Math.round(rt);

strPennies = new String (rt);

len = strPennies.length;

rt = strPennies.substring(0, len - 2) + "." + strPennies.substring(len - 2, len);


form.MinMonthlyPaymnt.value = rt;

}
</script>

 
Hi,

You can make it look like it doesn't appear inside a box by removing the border using CSS.... like this

[tt]<INPUT TYPE="text" VALUE="123" STYLE="border:0px;">[/tt]

This should give you an idea to get on with your project!

Good Luck §;O)


Jakob
 

You can place a DIV or SPAN on the page, with an ID:

Code:
<div id="minMonthlyPaymentDiv"></div>

and then write to it thus:

Code:
document.getElementById('minMonthlyPaymentDiv').innerHTML = 'Your Value Here';

Hope this helps,
Dan
 
Using Dan's suggestion I'm sure you'll want to keep your original values as well, so be sure not to overwrite what was originally in the div or span (or an iframe would work too, but that's a bit more difficult)

Code:
document.getElementById('minMonthlyPaymentDiv').innerHTML [red]+=[/red] 'Your Value Here';

-kaht

banghead.gif
 
great! thank you so much everyone, all those suggestions worked a charm, but I am going to stick with the super elegant DIV suggestion, as it means i won't have to worry about people being able to type in and modify the result of the calculation.

thank you again! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top