Forum Moderators: open

Message Too Old, No Replies

Update a form summary

         

ti2d

4:32 pm on Jun 13, 2006 (gmt 0)

10+ Year Member



I'm looking to create a form, that at the bottom has a summary section, and also generates a payment total. this is the basic outline:

<form name="order">
<input type="text" name="name" />
¦¦¦¦¦¦¦¦¦More fields¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦More fields¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦More fields¦¦¦¦¦¦¦¦¦¦
¦¦¦¦¦¦¦¦¦More fields¦¦¦¦¦¦¦¦¦¦

*Javascript code to display the value of name"
</form>

This is what I currently have, which doesn't work:

<script language="JavaScript">
<!--
function showData()
{ document.write(document.order.name.value);
}
//-->
</script>

when the value of name is changed, it goes to a new document with the value, how do I make it write the value without changing the rest of the document?

Your help is greatly appreciated!

jshanman

4:45 pm on Jun 13, 2006 (gmt 0)

10+ Year Member



Something like this?

<form name="order">
<input type="text" name="name" onkeyup="showData(this)"/>

<div id="total"></div>
</form>
<script type="text/javascript">
function showData(obj) {
document.getElementById("total").innerHTML = obj.value;
}
</script>

OR if you wanted to generate the total of all fields:

function showData(obj) {
var f = obj.form;
var total = 0;
for(i=0; i<f.elements.length; i++){
if(f.elements[i].type == "text") total = (parseInt(f.elements[i],10)!= "NaN")? total + parseInt(f.elements[i],10) : total;
}
document.getElementById("total").innerHTML = total;
}

- JS

ti2d

6:35 pm on Jun 13, 2006 (gmt 0)

10+ Year Member



ok, now how do I multiply the value of 2 elements together?
for instance:

<div id="total"></div>
<script type="text/javascript">
function showData(obj)
{
document.getElementById("total").innerHTML = obj.value;
}
</script>
<div id="totalb"></div>
<script type="text/javascript">
function showDatab(obj)
{
document.getElementById("totalb").innerHTML = obj.value;
}
</script>

how do I multiply the outpu of those two?