Membership is FREE, giving all registered users unlimited access to every Acorn Domains feature, resource, and tool! Optional membership upgrades unlock exclusive benefits like profile signatures with links, banner placements, appearances in the weekly newsletter, and much more - customized to your membership level!

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.

The Rule #1

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

Members online

Premium Members

Latest Comments

New Threads

Domain Forum Friends

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
      There are no messages in the current room.
      Top Bottom