Entry
I am working with an invoice form. I want my calculations to not display in a text field. How?
Dec 9th, 2003 15:47
Jean-Bernard Valentaten, Christine Schroeder,
Use hidden inputfields if you need to send them, or build the
querystring instead of just submitting.
Let's say you had three text fields containing values that you use to
culculate something, which is then stored in a var called 'result':
in HTML body:
<form id="myForm" ...>
...
<input type"button" id="mySubmit" value="Submit"
onClick="calculateAndStore();">
<input type="hidden" id="Result" value="">
...
</form>
With hidden inputfields:
function calculateAndStore()
{
var result;
var ...
//do something with the values from the textfields
document.getElementById('Result').Value = result;
document.getElementById('mySubmit').Submit();
}
This will submit the inpufields and the hiddenfields, so you can safely
get them just like you're used to, no matter which submit method you
choose.
Building a query string:
fucntion calculateAndStore()
{
var querystring;
var result;
var textfields[N];
//do something with the values from the textfields
querystring = 'http://www.myurl.com/somepage.php?';
for(var i=0; i<textfields.length; i++)
{
querystring += '?TextField' + i + '=' + textfields[i] + '%';
}
querystring += 'Result=' + result;
document.location.href = querystring;
document.loaction.reload();
}
pretty easy but not very flexible. this simulates a form submit using
the 'GET' method.
HTH,
Jean