<input type="text" id="field1"> <input type="text" id="field2">
let field1 = document.getElementById("field1").value; let field2 = document.getElementById("field2").value; let combined = field1 + field2; console.log(combined);
In this code, we first use
document.getElementById() to get references to the two input fields, and then use the
value property to get the values entered by the user.
Next, we concatenate the values of
field2 using the
+ operator and store the result in the
Finally, we log the value of the
combined variable to the console.
This is just one example of how you can combine data from two fields into one variable. You can use similar techniques to combine data from fields of other types, such as select elements or checkboxes.