Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I am trying to pass some values from HTML to HTML without using code behind. I have a function of java script which do the work but not as I want. I want that the values coming from one page to second, can be stored and shown in label instead of openly writing it on HTML page and I am not able to do so. Can anyone please tell me where am I going wrong ?
Here is my code:
JavaScript
params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
var lbl = document.getElementById('<%=lbl.ClientID%>');
lbl.innerHTML=firstname.


and this is my html code on second page:
ASP.NET
<form id="form1" runat="server">
<asp:Label ID="lbl" runat="server" Text="Label"></asp:Label>
   </form>
"



and here is my code on first page:
HTML
<form type=get action="second.aspx">
<table>
<tr>
<td>First Name:</td>
<td><input type="text" name="firstname" size="10"></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type="text" name="lastname" size="10"></td>
</tr>
<tr>
<td>Age:</td>
<td><input type="text" name="age" size="10"></td>
</tr>
<tr>
<td colspan=2><input type="submit" value="Submit">
</td>
</tr>
</table>
</form>
Posted
Updated 12-Aug-12 21:08pm
v4
Comments
StianSandberg 13-Aug-12 2:14am    
What is failing? Does document.write("firstname" + firstname); works? Do you even get the params?

Your line:
var lbl = document.getElementById('<%=lbl.ClientID%>')
But I don't see any servercontrol with an ID "lbl"?
Taresh Uppal 13-Aug-12 2:57am    
see the Question now
Taresh Uppal 13-Aug-12 3:03am    
no is is not failing at all... Wat I want is just to show this data in labels instead of document.write(etc etc)...
I just want to use labels and set their text property to the values coming in first name, last name,age etc
Sergey Alexandrovich Kryukov 16-Aug-12 2:57am    
About "java script". Such thing cannot exist -- Java is not a scripting language. If you mean JavaScript, don't call it "java script". JavaScript and Java are unrelated.

I see you fixed it, but old incorrect title sneaked in your most recent question... perhaps you edit it there, to avoid confusion.
--SA

This browser specific issue. Try this
JavaScript
var lbl = document.getElementById('<%=lbl.ClientID%>');
if(lbl !=null)
{
lbl.innerHTML=firstname;
lbl.innerText=firstname;
lbl.textContent =firstname;
}
 
Share this answer
 
Comments
Taresh Uppal 13-Aug-12 5:07am    
Hello pradeep..thanx a lot for ur seuggestion. But still the label is empty !
Taresh Uppal 13-Aug-12 5:29am    
No its not a browser specific issue.... its not even working on internet explorer !
pradiprenushe 13-Aug-12 6:04am    
does lbl having value or it is null?
Taresh Uppal 13-Aug-12 6:15am    
the js i have written is on html markup...how can i check that using breakpoints ?
pradiprenushe 13-Aug-12 6:26am    
use
alert(lbl);
This is not client side task.
This is server side task (IMHO).
So use for example PHP.
 
Share this answer
 
Comments
Taresh Uppal 13-Aug-12 1:57am    
could you please help me how to achieve it ?
Taresh Uppal 13-Aug-12 2:48am    
I just want that the values coming in first name should be visible in label instead of writing it openly on the browser, I am trying to do this because later I have to use these values to process something. Anyone has better idea to achieve this ?
Style-7 13-Aug-12 2:51am    
Hmm.
I see you want to edit a record of data base (name, age etc..)
So in first page client enter ID (or login information) and press button submit. Submit button link to second PHP page. By PHP parser you can call to data base and create the page dynamically and pass it to client.
See more http://www.w3schools.com/php/default.asp
Taresh Uppal 13-Aug-12 2:57am    
I am using asp.net and c# and all this javascript... not php...I am bit confused :(
Style-7 13-Aug-12 2:58am    
BUT!
You can use special global array for pass parameters from 1 page javascript to 2 page javascript.

localStorage["MY_OPTIONS"] = 1; //store
opt = localStorage["MY_OPTIONS"]; //read

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900