Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. Share your own thoughts and experience, accounts may be terminated for violations.

simple javascript nightmare

Status
Not open for further replies.
Joined
Mar 19, 2008
Posts
334
Reaction score
2
Hopefully really easy for someone with even a basic understanding of javascript.

I've 'written';) a function which collects the info from a form field:

var justhow;
function calculate(select)
{
justhow = document.forms[0].howmany.value;
}

When i try to call the bugger later on

document.write('<input type="text" name="total" size="10" value="' + justhow + '">');

it comes back as undefined.


I know it works fine as if I move the document.write into the function it does the calculation (but in a new page?!?!?)

I thinkits something to do with global/local variables but after reading about 50 different tutorials its still not working.

Can anyone help?

Thanks
 
Hi

This should help:
var justhow;
function calculate(){
justhow = document.getElementById('howmany').value;
document.getElementById('total').value = justhow;
}

Then in your page you would need the following form fields:
<input type="text" id="howmany" size="10" value="" onkeyup="javascript:calculate(this.value)">
<input type="text" id="total" size="10" value="">

Whenever the value of field id "howmany" is changed, the value of field id "total" will be updated.

Hope this helps!

Craig
 
Status
Not open for further replies.
Top Bottom