954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

HIDDEN Values <==Java Script Function Return value

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>


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>


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.:rolleyes:

parani
Newbie Poster
4 posts since Jul 2006
Reputation Points: 10
Solved Threads: 0
 

you're not calling the function, you're writing the function name. calling the function is only possible from a

MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 

sorry, my mistake, that first example should be:

<body onload="document.forms[0].elements['uname'].value = GetParam(username);">
...same as before...
</body>
MattEvans
Veteran Poster
Moderator
1,386 posts since Jul 2006
Reputation Points: 522
Solved Threads: 64
 

Hi
I know I am late, but can be helpful for people seeking response for this kind of questions :) Here is one of the possible solution:
In your existing function

function GetParam(rname) {
..
..
//before returning
var unameElement = document.getElementById('unameid');
if (unameElement == null) {
 var udiv = document.getElementById('unamediv');
 var element1= document.createElement('INPUT');
 element1.type="hidden";
 element1.setAttribute('id','unameid');
 element1.setAttribute('name','uname');
 element1.setAttribute('value',uname);
 udiv.appendChild(ele1);
}else {
 unameElement.setAttribute('value',uname);
}
..
//may be now you do not need return stmt
}
</script>

<body>
<form name="page2" method=get action="page3.html">
<div id="unamediv"></div>
..
</form>
</body>
</html>
amiivas
Newbie Poster
1 post since Oct 2011
Reputation Points: 10
Solved Threads: 0
 

4 1/2 years old post >_

Taywin
Posting Virtuoso
1,727 posts since Apr 2010
Reputation Points: 229
Solved Threads: 239
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You