Mark Drelinger
asked on
javascript to put IP into text field not working
javascript error
Not sure if I'm just being silly, but can't seem to get this script to work
function GetIP()
{
var strIP
strIP = Request.ServerVariables("H TTP_X_FORW ARDED_FOR" );
If strIP = "" Then strIP = Request.ServerVariables("R EMOTE_ADDR ");
IP = strIP;
document.form1.User_IP.val ue = IP;
}
Not sure if I'm just being silly, but can't seem to get this script to work
function GetIP()
{
var strIP
strIP = Request.ServerVariables("H
If strIP = "" Then strIP = Request.ServerVariables("R
IP = strIP;
document.form1.User_IP.val
}
you can't get IP address via client side javascript. this got to be done at server side instead.
Hi Mark,
The code you have written looks like classic ASP 3.0 code. It executes on server and then sets IP in a form. If you post the entire code I will be able to tell you why it does not populate on the form.
Regards,
Chinmay.
The code you have written looks like classic ASP 3.0 code. It executes on server and then sets IP in a form. If you post the entire code I will be able to tell you why it does not populate on the form.
Regards,
Chinmay.
Accessing headers from Javascript is possible + likely more complex than you imagine.
How you do this relates to many factors.
https://stackoverflow.com/ questions/ 220231/acc essing-the -web-pages -http-head ers-in-jav ascript provides a good overview of various methods of header access.
How you do this relates to many factors.
https://stackoverflow.com/
ASKER
I might have been overthinking it since I only needed internal IP address.
This seemed to work
<input name="User_IP" type="hidden" id="User_IP" value="<%=Request.ServerVa riables("R EMOTE_ADDR ")%>">
Is this a bad practice ?
This seemed to work
<input name="User_IP" type="hidden" id="User_IP" value="<%=Request.ServerVa
Is this a bad practice ?
Is this a bad practice ?any particular reason you want to show the IP address in your page?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks to all - I split the points because everyone was helpful...