Skip to content
Advertisement

Trying to learn php with html but I am having trouble submitting a form with a variable that is given by some javascript?

In the Html code below I grab the Ip address of the client and display it to them. I am still learning Javascript however and I am very confused with the line “$(“#gfg”).html(data.ip);” How would you rewrite this line to be more understandable? Additionally within the html file I would like to submit the information contained within gfg to the php form! I am very uncertain how to do this. :/ Sorry for the basic questions I am very new to this and still trying to understand just how javascript and php works. If there are any materials that you believe would help me please link them and I will be sure to study them!

HTML Script:

JavaScript

PHP Script:

JavaScript

Advertisement

Answer

You can use Ajax to send the data to server.

NOTE: Your file should have .php extension not .html and if you are on local machine you should run it on local server like wampserver to work.

HTML:

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement