PDA

View Full Version : Hidden Value <== Javascript Return Function


parani
04-12-2007, 01:40 PM
Hi

Can you please go through the HTML files and let me know where am I going wrong?

Page1.html :

<html>
<head>
<title>PAGE 1</title>
</head>
<body>

<form action="page2.html" method="get" name="LoginForm" id="LoginForm">

Username : <input name="username" size="20">

Password :<input name="password" type=password size="20">

<input type="submit" name="Login" value="Login" >
<input type="reset" name="Reset2" value="Reset">
</form>
</body>
</html>
[/SIZE]


Page2.html :

<html>
<head>
<title> Page2.html </title>
<script type="text/javascript">
function GetParam(rname)
{

var rstart=location.search.indexOf("?"+rname+"=");
if (rstart<0) rstart=location.search.indexOf("&"+rname+"=");
if (rstart<0) return ' ';
rstart += rname.length+2;
var end=location.search.indexOf("&",rstart)-1;
if (end<0) { end=location.search.length; }
var result='';
for(var i=rstart;i<=end;i++)
{
var c=location.search.charAt(i);
result=result+(c=='+'?' ':c);
}

return unescape(result);

}
</script>

<body>
<form name="page2" method=get action="page3.html">
<input type="hidden" name="uname" value=GetParam(username)>
<input type="button" name="button" value="click">
</form>
</body>
</html>[/SIZE]



When I tried to invoke GetParam(Username) javascript function, it didnt get the hidden element "UNAME" value instead it returned "GetParam(username)" itself.Can you put your ideas into this?

In Page3.html, I should be able to get the Hidden Values and Name for INPUT "UNAME".Is there any concept available??

Regards,
Parani.

Mr J
04-12-2007, 07:00 PM
I would be inclined to use the split() method

<html>
<head>
<title> Page2.html </title>
<script type="text/javascript">

function GetParam(rname){
if (location.search.length > 0){
dataPassed = location.search.substring(1)
document.page2.uname.value=dataPassed.split("&")[0].split("=")[1]
}
}
</script>

<body onload="GetParam('username')">
<form name="page2" method=get action="page3.html">
<input type="text" name="uname" value="">
<input type="button" name="button" value="click">
</form>
</body>
</html>