<!DOCTYPE html>
<html>
<head>
<title>This is a test</title>
</head>
<body>
<form id="form1">
Size: <input type="number" name="sizes" size="10"><br>
Bow: Yes<input type="radio" name="bow" value=5 />
No <input type="radio" name="bow" value=0 /><br>
Stern: Yes<input type="radio" name="stern" value=5 />
No<input type="radio" name="stern" value=0 />
</form>
<button onclick="outputsize()">Submit</button>
<script>
function outputsize() {
var x,y,b,s,sizes;
x=document.getElementById("form1") ;
y=x.elements["sizes"].value;
b=x.elements["bow"].value;
s=x.elements["stern"].value;
document.getElementById("demo").innerHTML=(y * 2+b+s);
}
</script>
<h1 id="demo"></h1>
</body>
</html>
I’ve edited your post for readability. When you enter a code block into the forum, precede it with a line of three backticks and follow it with a line of three backticks to make easier to read. See this post to find the backtick on your keyboard. The “preformatted text” tool in the editor (</>
) will also add backticks around text.
Thank you. I was wondering how to make the post viewable.
You could also use the Number function to convert strings to numbers. You need to convert the input values because they are strings.
y= Number(x.elements["sizes"].value);
b= Number(x.elements["bow"].value);
s= Number(x.elements["stern"].value);
The Number Function did the trick. I was at a lost, but that makes complete sense.. Thank you so much for the helpful advice.
Thank you for your suggestion. Using the Number Function was able to get me the result I was looking for.