aca te dejo otro ejemplo que usa el getElementById() que a mi modo de ver es mas simple
Código PHP:
Ver original<!DOCTYPE html>
<html>
<head>
<script>
function greeting()
{
//aca vas inicializando las variables con el id de los campos de form
var fname = document.getElementById('fname').value;
var fedad= document.getElementById('fedad').value;
document.writeln(fname+fedad)
}
</script>
</head>
<body>
<form name="frm1" action="tryjsref_form_onsubmit.htm" onsubmit="greeting()">
Nombre<br>
<input type="text" id="fname"><br>
Edad<br>
<input type="text" id="fedad">
<input type="submit" value="Submit">
</form>
</body>