I have two input fields and I want to add the value of one them to another. Here is what I have so far:
HTML
<input id="server" type="text" value="www.google.com">
<input id="port" type="text">
<button onclick="appendPort()">Save</button>
function getPort() {
let portValue = document.getElementById('port').value;
}
function appendPort(portValue) {
getPort();
console.log(portValue);
}
www.google.com123
123
portValue
undefined
appendPort
doesn't recieve an argument. It should use the return value of getPort
:
function appendPort() {
var portValue = getPort(); // get the value returned by getPort and store it in portValue
console.log(portValue);
}
and getPort
should return it:
function getPort() {
return document.getElementById('port').value; // return something to be used by appendPort
}