I'm trying to write a script to process form data within a simple offline HTML page. I lifted the first four variables I'm trying to pull through as an example. I can get a simple example to work like the one found here https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_form_elements_index but I'm struggling to expand it to multiple variables as below.
Am I approaching the two JavaScript functions wrong for this use?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript within HTML</title>
<script language = "JavaScript">
function get_dropdown (fieldname) {
Item = form.fieldname.selectedIndex;
Result = form.fieldname.options[Item].text;
return Result;
}
function getval (form) {
var Customer_Name = form.customer_name.value;
var Asset_Name = form.asset_name.value;
var Asset_Attribute = get_dropdown (asset_dropdown);
var Sub_Attribute = get_dropdown (sub_dropdown);
var Answer = Customer_Name + Asset_Name + Asset_Type + Sub_System;
document.getElementById("output1").innerHTML = Answer;
}
</script>
</head>
<body>
<form name = "agc_ira" method="get" action="" >
<fieldset>
<legend>Assessment Data</legend>
<table>
<tr>
<td>Customer Name:</td>
<td><input type="text" name="customer_name"></td>
</tr>
<tr>
<td>Asset Name:</td>
<td><input type = "text" name="asset_name"></td>
</tr>
<tr>
<td>Asset Attribute:</td>
<td><select name="asset_dropdown">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select></td>
</tr>
<tr>
<td>Sub-Attribute:</td>
<td><select name="sub_dropdown">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
</select></td>
</tr>
</table>
</fieldset>
<br><input type="button" name="runmodel" value="Run" onclick="getval()">
<br>
<p id="output1"></p>
</form>
</body>
</html>