0

Well, I'm really new into JS and I'm actually more into C++, but I decided to give it a try since I'd love to develop some online games, using the new Canvas element HTML5 is providing. But before that i need to get the basics.
What I'm trying to do here is a web application capable of solving some High School math problems related to Sine, Cosine, Tangent....

But I'm getting an "Undefined" Error, when trying to run a simple test. Here's the code, It's in spanish, but I think It's pretty much self-explaining, though I've modified the important parts

HTML!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript" src="FuncionesTrigonometricas.js"></script>
<title>Funciones trigonometricas</title>

</head>
<body>

Funcion Inicial
<FORM name="myForm"> 
<select name="InitialFunction" onChange='test()'>
<option SELECTED> --Please, select a trigonometric function -- </option>
<OPTION VALUE="sin"> Seno </option>
<option value="cos"> Coseno </option>
<option value="tan"> Tangente </option>
<option value="cot"> Contangente </option>
<option value="sec"> Secante </option>
<option value="csc"> Cosecante </option>
</select>
</form>
<br>

</body>
</html>

Javascript!

var InitialFunctionJS = document.myForm.InitialFunction.value;

function test() {
	alert(InitialFunctionJS);
}

I mean, the alert does shows, but it says: "Undefined"
P.D. I tried: document.write(InitialFunctionJS); , same result.

3
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by pato wlmc
0

Hi, select does not have a value field.

This should help if you'll add a ID attribute for your select tag.

var InitialFunctionJS= document.getElementById("InitialFunction").options[document.getElementById("InitialFunction").selectedIndex].value;
0

Please try this code.

function test() {
	var InitialFunctionJS = document.myForm.InitialFunction.value;
	alert(InitialFunctionJS);
    }

Edited by haleel: n/a

0

Please try this code.

function test() {
	var InitialFunctionJS = document.myForm.InitialFunction.value;
	alert(InitialFunctionJS);
    }

Thanks! That totally worked :D

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.