Hey,

I have very basic code that I am tinkering with as I learn new JS functions or techniques etc. So far I have:

It is pretty basic. The user enters three numbers, x, y and z then clicks a radio button. That calls the validate function which checks the values are not null and are not numbers. If true an alert is displayed, else it calls the radio_selection function(). This works out which radio button was chosen then calls the appropriate function. The functions perform the calculations it is supposed too and then displays an alert. Easy, basic, simple!Code:<html> <head> <script type="text/javascript"> function validate() //validate the form1 values { if (isNaN(document.form1.x.value) || isNaN(document.form1.y.value) || isNaN(document.form1.z.value)) { alert("Please enter a value for x, y and z"); } else { radio_selection() //call the function } } </script> <script type="text/javascript"> function radio_selection() { chosen = "" len = document.form1.r1.length //determine which radi button was checked for (i = 0; i <len; i++) { if (document.form1.r1[i].checked) { chosen = document.form1.r1[i].value } } if (chosen == "smallest number") { math_smallest() } else if (chosen== "largest number") { math_largest() } else if (chosen == "mean") { math_mean() } } </script> <script type="text/javascript"> function math_largest() { a = Math.max(Number(document.form1.x.value),Number(document.form1.y.value)) b = Math.max(Number(a),Number(document.form1.z.value)) alert("The largest number of " + document.form1.x.value + ", " + document.form1.y.value + " and "+ document.form1.z.value + " is " + b); } </script> <script type="text/javascript"> function math_smallest() { a = Math.min(Number(document.form1.x.value),Number(document.form1.y.value)) b = Math.min(Number(a),Number(document.form1.z.value)) alert("The smallest number of " + document.form1.x.value + ", " + document.form1.y.value + " and "+ document.form1.z.value + " is " + b); } </script> <script type="text/javascript"> function math_mean() { a = (Number(document.form1.x.value) + Number(document.form1.y.value) + Number(document.form1.z.value)); // find the sum of the values b = Number(a/3); c = Math.round(Number(b)*100)/100; //number rounded to the two decimal places alert("The mean of " + document.form1.x.value + ", " + document.form1.y.value + " and "+ document.form1.z.value + " is " + c); } </script> </head> <body> <h3>Please Enter three numbers</h3> <form name="form1"> <font>Number 1  </font><input type="text" name="x" value="x" size="5"><br /> <font>Number 2  </font><input type="text" name="y" value="y" size="5""><br /> <font>Number 3  </font><input type="text" name="z" value="z"size="5"><br /><br /> <input type="radio" name="r1" value="smallest number" onclick="validate()">Smallest Number <input type="radio" name="r1" value="largest number" onclick="validate()">Largest Number <input type="radio" name="r1" value="mean" onclick="validate()">The Mean </form> </body> </html>

Now, I wanted to make document.form1.x.value a global variable that would be used in all the functions, rather than having to type it out long. So document.form1.x.value become x.

I tried having all the functions within one script, and then adding x = document.form1.x.value for x, y and z, then followed by the functions. However, this didn't work, I just got no response when selecting a radio button.

Does anyone have any ideas or helpful links to help me solve this?