Enjoy unlimited access to all forum features for FREE! Optional upgrade available for extra perks.

simple javascript nightmare

Status
Not open for further replies.
Joined
Mar 19, 2008
Posts
337
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.

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Featured Services

Sedo - it.com Premiums

IT.com

Premium Members

AucDom
UKBackorder
Be a Squirrel
Acorn Domains Merch
MariaBuy Marketplace

New Threads

Domain Forum Friends

Other domain-related communities we can recommend.

Our Mods' Businesses

Perfect
Service
Laskos
*the exceptional businesses of our esteemed moderators
Top Bottom