Function return value

Hi guys i am new to js, trying to do simple code and i cant find what is wrong with it. All i want to do is write function answer into label text. How do i do that and why this dont work? i saw alot of tutorials on web where this one works fine, but not to me… help :smiley:

<html>
<head>
<title>Skaiciuokle</title>
<link rel="stylesheet" type="text/css" href="1.css">
<script type="text/javascript">
function calc()
{
var moketi,
    suma = document.getElementById("suma").value*1,
	laik = document.getElementById("laikotarpis").value*1;

moketi = suma+laik;

return moketi;
}

</script>
</head>
<body>
    <div id="main">
	   <form action="" method="post">
	      skolinama suma:<br>
	      <input type="number" id="suma"><br>
		  laikotarpis:
		  <select id="laikotarpis">

<           <script type="text/javascript">
		     for(var i=1;i<20;i++)
			 {
			 document.write("<option value="+i+">"+i+"</option>")
			 }
			 </script>
		   </select><br>
		
		  <input type="submit" value="apskaiciuoti" onclick="calc()">
	   </form>		
	   Moketi per menesy: <label id="label1"><script>document.write(calc()) </script></label>
	
	
	
	</div>
</body>
</html>

i tried this one too

function calc()
{
var moketi,
    suma = document.getElementById("suma").value*1,
	laik = document.getElementById("laikotarpis").value*1;

moketi = suma+laik;

document.getelementbyid(label1).innerHTML= moketi;
}

it shoud work> right???

Hi there,

Welcome to the forums :slight_smile:

This:

document.getElementById("laikotarpis").value

will return a string, which you cannot multiply by one (it will return NaN)

You need to do:

Number(document.getElementById("suma").value)