...

View Full Version : Filling the Value= Part of HTML With JS



elogicmedia
07-15-2004, 03:17 AM
Hi,
I have this Javascript that I use to calculate my budget planner.
Everything works however when I press calculate, the outcome works in to the form as it needs to but

when I view the source code, the value part of the imput tag is still blank
i.e. <input name="rent" type="text" size="15" id="rent" value="">
When the Tag reads 150.00 from the javascript calculations.

Does anyone know how I can fill this part of the html (value) as I want to use a printer friendly

version button (php script) to print the whole page, these values are not passed over because of the

empty 'value'.

Scripts are below, Thanx in Advance.

ADAM

ONLINE VERSION to see what I mean: http://clients.elogicmedia.com.au/qef/loan_budget.php

Javascript:
<script language="javascript">
function budget_Calc()
{
var java_salary = document.FormPlanner.salary.value - 0;
var java_ao_salary = document.FormPlanner.ao_salary.value - 0;
var java_o_salary = document.FormPlanner.o_salary.value - 0 ;
var java_g_benifits = document.FormPlanner.g_benifits.value - 0 ;

var java_rent = document.FormPlanner.rent.value - 0;
var java_c_loan = document.FormPlanner.c_loan.value - 0;
var java_p_loan_1 = document.FormPlanner.p_loan_1.value - 0;
var java_p_loan_2 = document.FormPlanner.p_loan_2.value - 0;
var java_cc1 = document.FormPlanner.cc1.value - 0;
var java_cc2 = document.FormPlanner.cc2.value - 0;
var java_cc3 = document.FormPlanner.cc3.value - 0;
var java_ele = document.FormPlanner.ele.value - 0;
var java_council = document.FormPlanner.council.value - 0;
var java_tele = document.FormPlanner.tele.value - 0;
var java_mobile = document.FormPlanner.mobile.value - 0;
var java_food = document.FormPlanner.food.value - 0;
var java_enter = document.FormPlanner.enter.value - 0;
var java_medical = document.FormPlanner.medical.value - 0;
var java_petrol = document.FormPlanner.petrol.value - 0;
var java_house_ins = document.FormPlanner.house_ins.value - 0;
var java_c_ins = document.FormPlanner.c_ins.value - 0;
var java_school = document.FormPlanner.school.value - 0;
var java_other1 = document.FormPlanner.other1.value - 0;
var java_other2 = document.FormPlanner.other2.value - 0;


var income = (java_salary + java_ao_salary + java_o_salary + java_g_benifits);

var outgoings = (java_rent + java_c_loan + java_p_loan_1 + java_p_loan_2 + java_cc1 + java_cc2 +

java_cc3 + java_ele + java_council + java_tele + java_mobile + java_food + java_enter + java_medical +

java_petrol + java_house_ins + java_c_ins + java_school + java_other1 + java_other2);

var outcome = (income - outgoings);

document.FormPlanner.totincome.value = income;
document.FormPlanner.totoutgoings.value = outgoings;
document.FormPlanner.total.value = outcome;
}

</script>


HTML FORM:
<FORM id=FormPlanner name=FormPlanner>
<table border="0" cellspacing="3" cellpadding="0">
<tr>
<td bgcolor="#0000FF" colspan="2" style="padding:5 "><strong style="color:#FFFFFF">MONTHLY

INCOME</strong></td>
</tr>
<tr>
<td>Take home pay:</td>
<td align="right"><input name="salary" type="text" size="15" id="salary"></td>
</tr>
<tr>
<td>Average overtime:</td>
<td align="right"><input name="ao_salary" type="text" size="15" id="ao_salary"></td>
</tr>
<tr>
<td>Other income:</td>
<td align="right"><input name="o_salary" type="text" size="15" id="o_salary"></td>
</tr>
<tr>
<td>Government benefits:</td>
<td align="right"><input name="g_benifits" type="text" size="15" id="g_benifits"></td>
</tr>
<tr>
<td><strong>Total Monthly Income:</strong></td>
<td align="right"><strong>$</strong><input name="totincome" type="text" size="15" id="totincome"

value=""></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td bgcolor="#0000FF" colspan="2" style="padding:5 "><strong style="color:#FFFFFF">MONTHLY

EXPENSES</strong></td>
</tr>
<tr>
<td>Rent, board or mortgage:</td>
<td align="right"><input name="rent" type="text" size="15" id="rent"></td>
</tr>
<tr>
<td>Car loan:</td>
<td align="right"><input name="c_loan" type="text" size="15" id="c_loan"></td>
</tr>
<tr>
<td>Personal loan 1:</td>
<td align="right"><input name="p_loan_1" type="text" size="15" id="p_loan_1"></td>
</tr>
<tr>
<td>Personal loan 2:</td>
<td align="right"><input name="p_loan_2" type="text" size="15" id="p_loan_2"></td>
</tr>
<tr>
<td>Credit card or store card 1:</td>
<td align="right"><input name="cc1" type="text" size="15" id="cc1"></td>
</tr>
<tr>
<td>Credit card or store card 2:</td>
<td align="right"><input name="cc2" type="text" size="15" id="cc2"></td>
</tr>
<tr>
<td>Credit card or store card 3:</td>
<td align="right"><input name="cc3" type="text" size="15" id="cc3"></td>
</tr>
<tr>
<td>Electricity and / or Gas:</td>
<td align="right"><input name="ele" type="text" size="15" id="ele"></td>
</tr>
<tr>
<td>Council rates:</td>
<td align="right"><input name="council" type="text" size="15" id="council"></td>
</tr>
<tr>
<td>Telephone:</td>
<td align="right"><input name="tele" type="text" size="15" id="tele"></td>
</tr>
<tr>
<td>Mobile:</td>
<td align="right"><input name="mobile" type="text" size="15" id="mobile"></td>
</tr>
<tr>
<td>Food:</td>
<td align="right"><input name="food" type="text" size="15" id="food"></td>
</tr>
<tr>
<td>Entertainment:</td>
<td align="right"><input name="enter" type="text" size="15" id="enter"></td>
</tr>
<tr>
<td>Medical aid:</td>
<td align="right"><input name="medical" type="text" size="15" id="medical"></td>
</tr>
<tr>
<td>Petrol / fuel:</td>
<td align="right"><input name="petrol" type="text" size="15" id="petrol"></td>
</tr>
<tr>
<td>House and / or content insurance:</td>
<td align="right"><input name="house_ins" type="text" size="15" id="house_ins"></td>
</tr>
<tr>
<td>Car insurance:</td>
<td align="right"><input name="c_ins" type="text" size="15" id="c_ins"></td>
</tr>
<tr>
<td>School and / or child care:</td>
<td align="right"><input name="school" type="text" size="15" id="school"></td>
</tr>
<tr>
<td>Other 1:</td>
<td align="right"><input name="other1" type="text" size="15" id="other1"></td>
</tr>
<tr>
<td>Other 2:</td>
<td align="right"><input name="other2" type="text" size="15" id="other2"></td>
</tr>
<tr>
<td><strong>Total Monthly Expenses:</strong></td>
<td align="right"><strong>$</strong><input name="totoutgoings" type="text" size="15"

id="totoutgoings"></td>
</tr>
<tr>
<td><INPUT id=Calculate onclick=budget_Calc() type=button value=Calculate name=Calculate> </td>
<td><INPUT id=Reset type=reset value=Reset name=Reset> </td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td bgcolor="#0000FF"><strong style="color:#FFFFFF">Monthly Disposable Income:</strong></td>
<td align="right"><strong>$</strong><INPUT id=total size=15
name=total></td>
</tr>
</table>
</form>

Kor
07-15-2004, 08:15 AM
when I view the source code, the value part of the imput tag is still blank
i.e. <input name="rent" type="text" size="15" id="rent" value="">


The value will be always as you said, "blank", but it doesn't mean that value is not there :D Take it as a, say, "virtual" value. As long as you keep the sesion, that value exists, and it is the value that user write it as an input.

So, which is your problem anyway? That "part of the html (value) " as you say it is "filled", as I said, not in a "real" mode, but in a "virtual" mode. You don't "see" it when view the source, but believe me, as long as you write in textfield a value, that value exists! :D

elogicmedia
07-15-2004, 09:02 AM
I needed a quick fix so what I did was re-write the script in php.

I needed the Value="" section to be filled because I was passing it to another page.

When done in php the Value="" section was filled easily.

Thanks

Kor
07-15-2004, 12:10 PM
Javascript is a client-side language, thus it can not write anything. If your new page is opened from the first using a javascript method (or it is loaded in a frame of iframe) and it has the same domain, the values can be passed, but if it is a full independent page javascript can not to this, so you need a server-side solution...

Can you explain exactly what you intend to do?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum