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:

Recommended Answers

All 4 Replies

you're not calling the function, you're writing the function name. calling the function is only possible from a <script> block or from an event handler attribute...

to call the function when the page has loaded; you could do this:

<body onload="document.forms.uname.value = GetParam(username);">
...same as before...
</body>

alternatively, replace the input with;

<script type="text/javascript">
document.write('<input type="hidden" name="uname" value="');
document.write(GetParam(username));
document.write('">');
</script>

(beware of the quoting here, each document.write uses a ' to quote its parameter, but there are " quotes inside each parameter..)


both of those methods are a bit 'hacky' for various reasons; neither is perfect and neither will work without Js. I'd certainly advise using PHP or similar to get the form data and alter the page; it's not a good job for javascript.

sorry, my mistake, that first example should be:

<body onload="document.forms[0].elements['uname'].value = GetParam(username);">
...same as before...
</body>

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>

4 1/2 years old post >_<

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.