View Single Post
Old 12-13-2012, 05:26 PM   PM User | #3
lzr
New to the CF scene

 
Join Date: Oct 2008
Posts: 7
Thanks: 1
Thanked 0 Times in 0 Posts
lzr is an unknown quantity at this point
Quote:
Originally Posted by felgall View Post
Best practice would be to move the JavaScript out of the HTML input tag and into a separate JavaScript file. Simply give the button an id and then you can attach as much onclick JavaScript as you need in the JavaScript file rather than in the HTML.

<input value="Calculate" id="calc" type="button">

Code:
document.getElementBiId('calc').onclick = function() {
   a(document.form.v1.value); // or whatever JavaScript you want
   b(document.form.v2.value);
};
Stephen,
Thank you for the script. Should this code be placed inside or outside the brackets that describe my js function a()? Actually, I tried both ways but it does not seem to work. I put the script for my function a() along with your code in an external .js file and changed html for the button exactly as wrote, but I am not proficient with js so maybe I am missing a simple thing. And I presume of course if all v1, v2, etc are described within the same function a(), I can put there
a(document.form.v1.value);
a(document.form.v2.value);
?
lzr is offline   Reply With Quote