View Full Version : Transfer of variables to php page

11-18-2010, 06:21 AM
I am trying to transfer the variables of the form (username & password )in the html page to the process.php page which are both given below. However I am not able to read those values from the process.php page. Can anyone please let me know what is going wrong here? Thanks in advance and appreciate your help.


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<script language="JavaScript" type="text/javascript">
function xor_str()
var username_val = document.forms['the_form'].elements["username"].value;
var password_val = document.forms['the_form'].elements["password"].value;
var xor_key='1234';
var username_res="";
var password_res=""
// XOR is done

//shifting the username_res to the left by 1 bit
//username_res = username_res << 1;
//shifting the password_res to the left by 1 bit
//password_res = password_res << 1;

//setting the xor'ed and shifted value for submission
document.forms['the_form'].elements["username"].value = username_res;
document.forms['the_form'].elements["password"].value = password_res;
//alert("UserName: " + username_res);
//alert("Password: "+ password_res);
the_form.submit(); // is this step right?


<form name="the_form" action="process.php" method="post">
<tr><td colspan="3">Username:<input type="text" name="username"></td></tr>
<tr><td>Password: <input type="text" name="password"></td><td colspan="2"><input type="button" onClick="xor_str()" value="Submit"></td></tr>


Process.php page

$username = $_POST['username'];
$password = $_POST['password'];

echo "You ordered ". $username . " " . $password . ".<br />";
echo "Thank you ";


11-18-2010, 07:29 AM
You were correctly referencing the form for the most part of the script then suddenly when submitting it, you access it directly by name?! That will not work in non-IE browsers.


11-18-2010, 07:36 AM
Thanks glenn for the reply. I tried using the syntax you suggested but still doesn't work. I am trying this in Mozilla Firefox, does that matter? I need to get this done ASAP. Please help me. THanks..

11-18-2010, 07:40 AM
What syntax did you try? Did you debug and check for the new values of the username and password fields? Are you sure the new values are getting set? Did you also check for any errors in the console?

11-18-2010, 07:44 AM
The one that you mentioned the_form.submit();

I am using the basic editor Editplus.

Regarding the username and password fields, those fields are getting updated with the encrypted values. The only problem I have is with transferring the variables to the php page. The page is not being redirected to the php page...

11-18-2010, 07:49 AM
I was not suggesting the code I posted was the one you need to use (you were already using it, right?), I was pointing out that this code was wrong. I said that you were referencing the form correctly (i.e. document.forms['the_form'].elements["username"].value) for the most part of the script but then when you submitted the form, you were referencing it wrong (i.e. the_form.submit())

11-18-2010, 07:53 AM
I tried documents.forms["the_form"].submit(); this too but did not work. Thats when I tried that and posted.. Any help?

11-18-2010, 07:58 AM
Does it go to process.php and just display a blank page?

11-18-2010, 07:59 AM
No its not going to that php page. Thats the problem :confused:

11-18-2010, 08:12 AM
Then there must be a js error. Did you check the js console to look for the error?

11-18-2010, 08:16 AM
I copied and pasted your code and changed the_form.submit() with documents.forms["the_form"].submit() and it worked for me in Firefox. The form was submitted successfully and the browser tried to load process.php.

(Ooppss..I just noticed this is my 10,000th post which makes me a Supreme Master coder! Yay! :))

11-18-2010, 08:29 AM
Wow thats terrific.. That calls for a party...:)

I am using a basic editor so no option of checking at console..

So it works for you ha? Does the php page load?

11-18-2010, 08:42 AM
I thought you were using Firefox?

11-18-2010, 09:09 AM
Sure I am but its not working for me :(

11-18-2010, 09:14 AM
Why can't you check the error console? Or better, check Firebug.