I want to check password field value after submiting the form by post method.
How can I get that value in HTML page using javascript
Example:
<form method="post" action="check.html">
<input type="Password" value="" name="pwd">
<input type="Submit" value="Submit" name="Submit">
</form>
I want the value of "pwd" in check.html
to check the authorisation.
I want to check password field value after submiting the form by post method.
How can I get that value in HTML page using javascript
Example:
<form method="post" action="check.html">
<input type="Password" value="" name="pwd">
<input type="Submit" value="Submit" name="Submit">
</form>
I want the value of "pwd" in check.html
to check the authorisation.
- Which server side language do you use? The script that processes the form should set the right value. – Felix Kling Commented Mar 21, 2011 at 7:09
- 3 Oh, I forgot to mention: Never authorize or authenticate the user at the client side as the user can easily manipulate the process. If you don't use a server side language, but doing everything with JavaScript, then you already lost. – Felix Kling Commented Mar 21, 2011 at 7:15
4 Answers
Reset to default 2you can try this alos
page1.php
<form method="POST" action="page2.php">
<input type="text" name="field" value="Enter value here" />
</form>
page2.php
<form method="POST">
<input type="text" name="field" value="<?php echo($_POST['field']) ?>" />
</form>
also you can do this with cookies also but using cookies is not a good option i guess.
another option you can use
file1.html
<Form name="frmDefault" action="file2.html" method="get">
<p>Item1: <Input Type="text" name="txtItem1"></p>
<p>Item2: <Input Type="text" name="txtItem2"></p>
<p><Input type="submit"></p>
</Form>
file2.html
<Script Language="Javascript">
<!--//
var arrArgs = location.search.substring(1).split("&");
for (var i=0; i<arrArgs.length; i++) {
document.write ('<p>' + arrArgs[i] + "</p>");
}
//-->
</Script>
<html>
<script type='text/javascript'>
function doSubmit() {
alert(document.getElementById('pwd').value);
document.getElementById('authfrm').submit();
}
</script>
<body>
<form id='authfrm' method='post'>
<input type='text' id='nick' />
<input type='password' id='pwd' />
<input type='button' onclick='doSubmit();' />
</form>
</body>
</html>
but remember, you can't access any values from html page. you need do assign action="check.php" or some other script engine.
You cannot get at a posted variable in an html page unless your check.html is not really an html page, but a server processed page with a rewrite rule to hide it is not really html
Some servers will not even allow you to post to html.
To get at the variable in javascript, you will need to GET the page - this will show the password in plain text in the url of the page.
I think you want to pletely rethink your approach and password protect the directory where your page is in, and use at least basic authentication to get at it depending on how secret you want it to be. If you just want your aunt to not see your page, then set a cookie in the form and check it in check.html
There is an existing post about it
For GET, there is a trick able to do it as below
var $_GET = {};
document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () {
function decode(s) {
return decodeURIComponent(s.split("+").join(" "));
}
$_GET[decode(arguments[1])] = decode(arguments[2]);
});
// display responses
var response = "";
for (var key in $_GET) {
response += key + ": " + $_GET[key] + ";";
}
alert(response);