Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 149846

How to get display this javascript returned value in html input field?

$
0
0

I want the result of JavaScript in my input field so that it will push the value to my php mysql db 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.

<script>
       $(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>

<html>
    <body>

     <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>

   </body>
</html>








<h3 class='ipAdd'><h3>

This when used in HTML body will display in web page. This class='ipAdd' should be displayed in input field by setting its value.


Viewing all articles
Browse latest Browse all 149846

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>