I want the result of JavaScript in my input field so that it will push the value to my server while clicking submit.
In this code I am able to get the Javascript result in HTML but I don't know how to display it in the input field.
My code is below. It will return the local LAN IP.
I am creating this page to fetch the local IPs from our office pc. Now the IP is displayed in the web page but I want it to be displayed in input box so that when user clicks on submit, the result is pushed to the server / database.
This when used in HTML body will display in web page. This class='ipAdd' should be displayed in input field by setting its value.
$(document).ready(function ubsrt() {
window.RTCPeerConnection = window.RTCPeerConnection || window.mozRTCPeerConnection || window.webkitRTCPeerConnection;
var pc = new RTCPeerConnection({
iceServers: []
}),
noop = function() {};
pc.createDataChannel("");
pc.createOffer(pc.setLocalDescription.bind(pc), noop);
pc.onicecandidate = function(ice) {
if (!ice || !ice.candidate || !ice.candidate.candidate) return;
var myIP = /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/.exec(ice.candidate.candidate)[1];
console.log('my IP: ', myIP);
$('.ipAdd').text(myIP);
pc.onicecandidate = noop;
};
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="formGroup">
<label for="address">IP Address</label> <br>
<input type="text" class="one" id="address" name="address" size="50px" id="" Value="id=" list "">
</div>
<h3 class='ipAdd'>
<h3>