tags:

views:

48

answers:

2

In one php file (file1.php), I execute another through

<form action="file2.php" method="POST">

yet within file2, I want to access html elements from file1.php, via document.getElementById(). Yet, the document object is different for file1 and file2.

How can I access file1's elements from within file2?

A: 

Why don't you try hiding in file2.php the elements that you still need?.

Just render them again with php in file2.php, and hide them via CSS, then they will be easily accesible through javascript.

Justanotheraspiringdev
what do you mean by render them again? If you mean just re-code the html, I would not gain the information which is particular to the elements in file1.php, as decided by the user.
wucnuc
+1  A: 

well rather then using javascript you can access what you need via PHP's $_POST function so if you had the elements name and password you could access them with:

$_POST['name'];
$_POST['password'];

so something like this for file2.php:

<?php
    if(array_key_exists('submit', $_POST))
    {
        $username = $_POST['name'];
        $password = $_POST['password'];

        echo("Hello $username, your password is $password");
    }
?>

That goes on the assumption of file1.php looking like:

<form action="file2.php" method="post">
    Username:
    <input type="text" name="name" />
    <br />
    Password:
    <input type="password" name="password" />
    <br />
    <input type="submit" name="submit" />
</form>
Marc Towler
great, this was the answer I needed!
wucnuc