jquery - Error while calling a Javascript function on HTML link click -
i have text box, html link & javascript function.
javascript function used client machine's ip-address. when click on link, trying call function & display result in textbox. however, fail obtain result.
this error getting.
uncaught typeerror: cannot read property 'ip' of undefined
my text box:
<input type="text" id="txtmyip" name="txtmyip"readonly>
my html link:
<a href="#" onclick="displayip();" >show ip address</a>
my javascript function:
var script = document.createelement("script"); script.type = "text/javascript"; script.src = "http://www.telize.com/jsonip?callback=displayip"; document.getelementsbytagname("head")[0].appendchild(script); function displayip(response) { document.getelementbyid("txtmyip").value = response.ip; }
you need separate jsonp request function , display function. example:
function displayip() { var script = document.createelement("script"); script.src = "http://www.telize.com/jsonip?callback=populateip"; document.head.appendchild(script); } function populateip(response) { document.getelementbyid("txtmyip").value = response.ip; }
Comments
Post a Comment