PDA

View Full Version : JavaScript and forms



Eclyps19
09-30-2006, 05:43 PM
So i made a script to calculate factorials using 1 to 20. It would display them on the page using document.write.

What I now want to do is make the start and end number user inputs using 2 forms and a button.

I'm not completely sure how to do this. Using just the default stuff I would think it's something like


onclick="factorial(document.form1.textfield, document1.form1.textfield2);"

in the buttons code. This doesn't work. I'm trying to kill 2 birds with 1 stone here. Passing arguments and reading input.

What am I doing wrong? I am not even sure if the whole document.form1 thing is even close to being correct.

I'll probably have tons of questions over the next few weeks, so thanks for helpin me out.

shachi
09-30-2006, 06:38 PM
onclick="factorial(document.form1.textfield.value, document1.form1.textfield2.value);"


this maybe ...

Twey
09-30-2006, 07:33 PM
If this is an <input type="button">, you should use:
onclick="factorial(this.form.elements['textfield'].value, this.form.elements['textfield2'].value);"... although this may be totally wrong since we don't have your code.

Eclyps19
09-30-2006, 07:49 PM
that should work, twey. The code is on my laptop that's not connected to the internet, but i believe that's the syntax i was looking for. thanks

mburt
09-30-2006, 08:18 PM
You can preview it even if you don't have the internet. Anything that's in your protocol browser (I think that's the right term) should be able to be viewed in a browser.

Eclyps19
09-30-2006, 10:58 PM
yes, but what I was saying was I don't have the internet on my laptop so I can't post the code on the forums.