Click to See Complete Forum and Search --> : Taking info from one place and putting it in another
rossi
11-12-2003, 10:27 AM
HI all,
i was wondering if any one can help..
i need to get information from the address bar into a HTML page, BUT its also got to be hidden so that the user can see it (ie it is his/hers username and password)
so it should take "login=900&pass=900" from the address bar and stick it in a form, so i get it by email and can see what user submited what.
hope yo can help..
thanks..
rossi
gil davis
11-12-2003, 10:54 AM
Add two hidden fields to your form. The page will automatically update the fields for you.
<form ...>
...
<input type="hidden" name="login">
<input type="hidden" name="pass">
</form>
If for some reason they do not update automatically (maybe I am wrong), add this script in the head and use the body onload event to run it:
<script>
function init() {
if (window.location.search != "")
{srch = window.location.search.substr(1).split("&");
ary = new Array();
for (var i=0; i<srch.length; i++)
{tmp = srch[i].split("=");
ary[tmp[0]] = tmp[1];}
for (var i in ary)
{document.formname[i].value = ary[i];} // fix "formname"
}
</script>
...
<body ... onload="init()">
rossi
11-12-2003, 11:10 AM
the first one you gave me doesnt work!
ill try the second option.
thanks
rossi
11-12-2003, 11:16 AM
i cant get round the second one....
do you understand what im trying todo??
i want info from the address bar, ie i have written a CGI script that member processes info and keep them logged in, it shows the username and password (ie..https://secure.co.uk/cgi-bin/member.cgi?page=email&login=900&pass=900)
i want to take
login=900&pass=900
and put it in my form in a hidden field, so that when the user submits, i will get there info in an email including username and password so i know who they!
hope thats more help.
thanks
ross
Charles
11-12-2003, 11:28 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
onload = function () {document.forms[0].URL.value = self.location.search.replace(/^\?/, '')}
// -->
</script>
<form action="" onsubmit="alert(this.URL.value); return false">
<div>
<input name="URL" type="hidden">
<button type="submit">Submit</button>
</div>
</form>
Just be aware, it will not do a thing for the 13% of users who do not use JavaScript.
gil davis
11-12-2003, 11:30 AM
Here is a complete working example.
<head>
<title>Loading hidden fields from a query</title>
<script>
function show() {
alert("login = " + document.f1.login.value + "\npass = " + document.f1.pass.value);
}
function init() {
if (window.location.search != "")
{srch = window.location.search.substr(1).split("&");
ary = new Array();
for (var i=0; i<srch.length; i++)
{tmp = srch[i].split("=");
ary[tmp[0]] = tmp[1];}
for (var i in ary)
{document.f1[i].value = ary[i];}
}
show();
}
</script>
</head>
<body onload="init()">
<form name="f1" onsubmit="return false">
<input type="hidden" name="login" value="">
<input type="hidden" name="pass" value="">
</form>
</body>
Charles
11-12-2003, 11:38 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<title>Example</title>
<script type="text/javascript">
<!--
onload = function () {if (/name=([^&])+/.test(window.location.search)) document.forms[0].name.value = unescape(RegExp.$1); if (/password=([^&])+/.test(window.location.search)) document.forms[0].password.value = unescape(RegExp.$1)}
// -->
</script>
<form action="" onsubmit="alert([this.name.value, this.password.value]); return false">
<div>
<input id="name" type="hidden">
<input id="password" type="hidden">
<button type="submit">Submit</button>
</div>
</form>
rossi
11-12-2003, 11:44 AM
charles the last ones no good, but the one you gave me befor is good, except it displas the who address bar! :rolleyes:
rossi
11-13-2003, 05:53 AM
Now none of them are working, can any one shed some light please??
im confused!
Charles
11-13-2003, 06:03 AM
Originally posted by rossi
Now none of them are working, can any one shed some light please??
im confused! You are doing something wrong. Post the URL so that we can find it.
rossi
11-13-2003, 06:56 AM
hmm ok
this is the head part:
<html>
<head>
<title>Update Email Address - Telephone account</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<script type="text/javascript">
<!--
onload = function () {if (/name=([^&])+/.test(window.location.search)) document.forms[0].name.value = unescape(RegExp.$1); if (/password=([^&])+/.test(window.location.search)) document.forms[0].password.value = unescape(RegExp.$1)}
// -->
</script>
</head>
and this is the body part:
<tr>
<td width="251" height="1"><strong><font size="2" face="Verdana">Re-enter
email address:</font></strong></td>
<td width="313" height="1"><font face="Verdana" size="1">
<input TYPE="text" NAME="Email_confirm" onChange="setName()" size="41">
</font></td>
</tr>
<tr>
<form action="" onsubmit="alert([this.name.value, this.password.value]); return false">
<div>
<input id="name" type="hidden">
<input id="password" type="hidden">
<button type="submit">Submit</button>
</div>
</form>
</tr>
<tr>
<td width="251" height="1"></td>
<td width="313" height="1"></td>
</tr>
<tr>
Still not working, it did work then stopped!! hmm weird
rossi
11-13-2003, 08:54 AM
sorted was a fault on my end!