PDA

View Full Version : problem with my functions. anyone to help please?



daniel curry
04-20-2013, 10:33 AM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MUSAU & KALONJI INTERNATIONAL</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="rule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
/* <![CDATA[ */
var masterCost = 0;
var cardiologyCost = 0;
var lightCost = 0;

<!-- the 3 first functions are working very well and i can get the output on the forms, but i dont know what is wrong with the 2 last functions. to calculate the VAT and the TOTAL VAT incl.--!>
function calcMasterCost(number) {
masterCost = number * 300;
calcTotalEstimate();
}
function calcCardiologyCost(item) {
cardiologyCost = item * 500;
calcTotalEstimate();
}
function calcLightCost(bintu) {
lightCost = bintu * 600;
calcTotalEstimate();

}

function calcTotalEstimate() {
var total = masterCost;
total += cardiologyCost;
total += lightCost;

document.forms[0].total.value = "$" + total.toLocaleString();
}

function calcVatEstimate(vatValue) {
var vatValue = document.getElementsByName("total");
vat1 += vatValue / (114*100);
document.forms[0].vat.value ="$" + vat1.toLocaleString();




}

function calcFinalTotal() {

var valT = document.getElementsByName("total")
var valV = document.getElementsByName("vat")
total2 += valT + valV ;
document.forms[0].total2.value = "$" + total2.toLocalString();




}




</script>

</head>

<body >
<div id="wrapper" >
<div id="header"> <img src="medical.jpg" alt="logo" style="float:left;margin-left: 10px; border-radius: 1em" width=100 height=100 /><h1>MEDICAL QUALITY SUPPLIER</h1></div>

<div id="nav"><h2 style="font-family: arial;text-align: center"> Navigation <h2>


<ul id="navlist" >
<li><a href="index.html"> Home </a></li>
<li><a href="product1.html"> Products </a></li>
<li><a href="orderForm1.html"> Order Here </a></li>
<li><a href="contact1.html"> Contact </a></li>
</ul>
</div>

<div id="article">
<p class="par"> Please provide the number of items you would like to purchase in the rubrics below, thank you</p>
<form>
<fieldset>

<legend> Make orders here please</legend>

<p><label class="order" for="master classic"> How many Littman Master Classic ii do you want? </label>

<input type="text" name="number" id="master classic" size="7" maxlength="7" onblur="calcMasterCost(this.value);"/>( R300/each) </p>


<p><label class="order" for="cardiology"> How many Littmann Cardiology III do you want? </label>

<input type="text" name="item" id="cardiology" size="7" maxlength="7" onblur="calcCardiologyCost(this.value);"/>( R500/each) </p>


<p><label class="order" for="lightweight"> How many Littmann LightWeight do you want? </label>

<input type="text" name="bintu" id="lightweight" size="7" maxlength="7" onblur="calcLightCost(this.value);" />( R600/each) </p>





<p><label class="order" for="total"> TOTAL VAT Exclu </label>

<input type="text" name="total" id="total" size="7" maxlength="7" onfocus="this.blur()" /> </p>


<p><label class="order" for="vat"> VAT </label>

<input type="text" name="vat" id="vat" size="7" maxlength="7" onblur="calcVatEstimate(vatValue)" /></p>

<p><label class="order" for="total2"> Total VAT Inclu </label>

<input type="text" name="total2" id="total2" size="7" maxlength="7" onfocus="this.blur()" /></p>






</fieldset>

<fieldset >
<legend> Enter your contact details below please </legend>

<p><label class="field" for="client name"> Client Name: </label>
<input type="text" name="client" id="client name" size=" 10" maxlength=" 10" /> </p>

<p><label class="field" for="client Email"> Client Email: </label>
<input type="text" name="client" id="client email" size=" 30" maxlength=" 30" /> </p>

<p><label class="field" for="client phone"> Client Phone: </label>
<input type="text" name="client" id="client Phone" size=" 30" maxlength=" 30" /> </p>

<p><label class="field" for="client address"> Client Address: </label>
<input type="text" name="client" id="client address" size=" 30" maxlength=" 30" /> </p>

<p>where is the address you provided?</p>

<label class="field" for="client house"> Your House
<input type="radio" name="client" value="house" id="client house" size=" 10" maxlength=" 10" /></label>



<label class="field" for="client office"> Your office
<input type="radio" name="client" value="office" id="client office" size=" 10" maxlength=" 10" /></label>

<label class="field" for="university"> Your University
<input type="radio" name="client" value="university" id="university" size=" 6" maxlength=" 6" /></label>





</fieldset>

<p><input type="submit" value="Submit the Form" />

<input type="reset" value="Clear the Form" /> </p>

</form>
</div>






<div id="sidebar">
<h3 style="text-align: center" >LITTMAN STETHOSCOPES</h3> <br /> <hr />
<img src="medical.jpg" alt="stethoscope" width=100 height= 100 style="margin-left:35px ;border-radius:2em " />
</div>

<div id="footer">jjjjjjjjjjjjjjjjjjjj
</div>

</body>

</html>

Mod's note:

daniel, in the future, please take the time to clearly explain your problem.
DD is a learning community, not a drop-off service. We're here to help *you* solve your problems.

"It doesn't work" is useless information. Some good, basic questions to keep in mind when asking for help:

What do you want to accomplish? What have you already tried? What problems have you encountered?
You might also consider making a reduced test case (http://css-tricks.com/reduced-test-cases/) using an online tool like jsfiddle (http://jsfiddle.net).

marain
04-23-2013, 11:05 AM
I lack the time, and probably the talent, to analyze your code. I do have general debugging suggestion: Isolate. Remove the parts that you know are working correctly. Or, if those parts are supposed to yield a particular value, just plug in that value, for use by the malfunctioning functions. Get the malfunctioning function to the smallest possible length. That will enable others to more easily spot the difficulty. Lastly, you should enclose code with
your code goes here .

Good luck.

A.

vwphillips
04-23-2013, 12:26 PM
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MUSAU & KALONJI INTERNATIONAL</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link href="rule.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
/* <![CDATA[ */
var masterCost = 0;
var cardiologyCost = 0;
var lightCost = 0;

//<!-- the 3 first functions are working very well and i can get the output on the forms, but i dont know what is wrong with the 2 last functions. to calculate the VAT and the TOTAL VAT incl.--!>
function calcMasterCost(obj) {
masterCost = number(obj) * 300;
calcTotalEstimate();
}

function calcCardiologyCost(obj) {
cardiologyCost = number(obj) * 500;
calcTotalEstimate();
}

function calcLightCost(obj) {
lightCost = number(obj) * 600;
calcTotalEstimate();
}

function number(obj) {
v=obj.value.replace(/\D/i,'');
v=v||0;
obj.value=v;
return v;
}

function calcTotalEstimate() {
var total = masterCost+cardiologyCost+lightCost;
document.forms[0].total.value = "$" + total.toLocaleString();
calcVatEstimate(total);
}

function calcVatEstimate(total) {
vat1 = total / (114*100);
document.forms[0].vat.value ="$" + vat1.toLocaleString();
calcFinalTotal(total+vat1)



}

function calcFinalTotal(v) {
v=Math.round(v*100)/100
document.forms[0].total2.value = "$" + v;




}




</script>

</head>

<body >
<div id="wrapper" >
<div id="header"> <img src="medical.jpg" alt="logo" style="float:left;margin-left: 10px; border-radius: 1em" width=100 height=100 /><h1>MEDICAL QUALITY SUPPLIER</h1></div>

<div id="nav"><h2 style="font-family: arial;text-align: center"> Navigation <h2>


<ul id="navlist" >
<li><a href="index.html"> Home </a></li>
<li><a href="product1.html"> Products </a></li>
<li><a href="orderForm1.html"> Order Here </a></li>
<li><a href="contact1.html"> Contact </a></li>
</ul>
</div>

<div id="article">
<p class="par"> Please provide the number of items you would like to purchase in the rubrics below, thank you</p>
<form>
<fieldset>

<legend> Make orders here please</legend>

<p><label class="order" for="master classic"> How many Littman Master Classic ii do you want? </label>

<input type="text" name="number" id="master classic" size="7" maxlength="7" onblur="calcMasterCost(this);"/>( R300/each) </p>


<p><label class="order" for="cardiology"> How many Littmann Cardiology III do you want? </label>

<input type="text" name="item" id="cardiology" size="7" maxlength="7" onblur="calcCardiologyCost(this);"/>( R500/each) </p>


<p><label class="order" for="lightweight"> How many Littmann LightWeight do you want? </label>

<input type="text" name="bintu" id="lightweight" size="7" maxlength="7" onblur="calcLightCost(this);" />( R600/each) </p>





<p><label class="order" for="total"> TOTAL VAT Exclu </label>

<input type="text" name="total" id="total" size="7" maxlength="7" onfocus="this.blur()" /> </p>


<p><label class="order" for="vat"> VAT </label>

<input type="text" name="vat" id="vat" size="7" maxlength="7" /></p>

<p><label class="order" for="total2"> Total VAT Inclu </label>

<input type="text" name="total2" id="total2" size="7" maxlength="7" /></p>






</fieldset>

<fieldset >
<legend> Enter your contact details below please </legend>

<p><label class="field" for="client name"> Client Name: </label>
<input type="text" name="client" id="client name" size=" 10" maxlength=" 10" /> </p>

<p><label class="field" for="client Email"> Client Email: </label>
<input type="text" name="client" id="client email" size=" 30" maxlength=" 30" /> </p>

<p><label class="field" for="client phone"> Client Phone: </label>
<input type="text" name="client" id="client Phone" size=" 30" maxlength=" 30" /> </p>

<p><label class="field" for="client address"> Client Address: </label>
<input type="text" name="client" id="client address" size=" 30" maxlength=" 30" /> </p>

<p>where is the address you provided?</p>

<label class="field" for="client house"> Your House
<input type="radio" name="client" value="house" id="client house" size=" 10" maxlength=" 10" /></label>



<label class="field" for="client office"> Your office
<input type="radio" name="client" value="office" id="client office" size=" 10" maxlength=" 10" /></label>

<label class="field" for="university"> Your University
<input type="radio" name="client" value="university" id="university" size=" 6" maxlength=" 6" /></label>





</fieldset>

<p><input type="submit" value="Submit the Form" />

<input type="reset" value="Clear the Form" /> </p>

</form>
</div>






<div id="sidebar">
<h3 style="text-align: center" >LITTMAN STETHOSCOPES</h3> <br /> <hr />
<img src="medical.jpg" alt="stethoscope" width=100 height= 100 style="margin-left:35px ;border-radius:2em " />
</div>

<div id="footer">jjjjjjjjjjjjjjjjjjjj
</div>

</body>

</html>