Skip to content Skip to sidebar Skip to footer

Passing HTML Form Data To Javascript Function

I've created a form with one drop down menu to choose from as well as three other text fields for users to input data. I need to perform calculations on the data the user inputs a

Solution 1:

You need to reference the value property on your inputs, just like you did with your select

document.write(document.getElementById("target_bodyfat_pct"));
document.write(document.getElementById("tw") + "</br>");

should be

document.write(document.getElementById("target_bodyfat_pct").value);
document.write(document.getElementById("tw").value + "</br>");

Also, consider creating a div for all the output, and writing it there.

<div id="yourOutputDiv"></div>

var results = document.getElementById("activity_level").value + "</br>" +
              document.getElementById("target_bodyfat_pct").value + 
              document.getElementById("tw").value + "</br>";

document.getElementById("yourOutputDiv").innerHTML = results;

Post a Comment for "Passing HTML Form Data To Javascript Function"