Forum Moderators: open

Message Too Old, No Replies

javascript variable to php

want html variable to be from js to php

         

ikbenhet1

12:38 am on Jan 14, 2004 (gmt 0)

10+ Year Member



I have a javascript function that reads a website's content in a string.

How do i pass the content from js to php? do i need encode the string in any way?
I've tried it with meta refresh, but it didn't work as expected. Have any tips?

Purple Martin

1:26 am on Jan 14, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Use JavaScript to put the information in a form field, then submit the form and use php to read it. The form field can be hidden, and if you don't want your page to disappear when the form submits you could put the form in a hidden iFrame so that only the iFrame gets submitted.

HTH

ikbenhet1

6:27 am on Jan 14, 2004 (gmt 0)

10+ Year Member



Thanks, that's what i was trying, but my code doesn't work, can anybody spot the error? The input field doesn't get populated.

content="";
var xmlhttp = new ActiveXObject("MSXML2.XMLHTTP");
xmlhttp.open( 'GET', 'http://www.example.com' , true);
xmlhttp.onreadystatechange = function(){
if (xmlhttp.readyState == 4)
content=xmlhttp.responseText;

}
xmlhttp.send(null);
document.write('<form action="http://www.example.com/tst.php" method="post"><input type="text" value="'+content+'" name="content1"><input type="submit" value="doen"></form>');

<edit> figured it out </edit>