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.
  • Welcome to AcornDomains.co.uk, a friendly community for UK domain investors, developers and anyone interested in domain names.

    Whether you're looking to buy or sell domains, learn more about the UK domain market, get feedback on your names, or simply chat with other domainers, you're in the right place. AcornDomains has been bringing together people from across the UK domain industry for many years, from complete beginners to experienced investors.

    Have a look around, join the discussions and, if you haven't already, create a free account and introduce yourself.

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