- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘JavaScript’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Home › Forums › JavaScript › Javascript to PHP
Hi, I need to send this to a php file without the current page being redirected to the php file. Can you do this?
document.getElementById("box").value
so at the moment that should equal ‘hello’ i would like to pass it to the php file as ‘hello’ which the php can treat as a variable.
Many Thanks
What you need to employ is the much-hyped AJAX. Since the process of setting up an AJAX connection is different for different browsers and IMHO adds quite a bit of unnecessary markup within the page itself, I would recommend using a JavaScript framework to accomplish this.
There are plenty of tutorials out there for basic AJAX communication, but here is a quick one: http://www.w3schools.com/Ajax/ajax_intro.asp.
Whether you use an HTTP GET or POST request, the parameter you pass will be available in php with $_REQUEST, so I think that will help you out.
There are plenty of tutorials out there for basic AJAX communication, but here is a quick one: http://www.w3schools.com/Ajax/ajax_intro.asp.
Whether you use an HTTP GET or POST request, the parameter you pass will be available in php with $_REQUEST, so I think that will help you out.
Also take a look at jquery or mootools…. writing ajax in just javascript can be painful
… and ofcourse don’t forget to test your thing with JavaScipt disabled aswell.
The bare function of the thing should never depend on JavaScript alone, one should be able to perform the core functionality also without JavaScript IMO.