Click to See Complete Forum and Search --> : Getting the value of a Label in new page
hkullana
January 4th, 2010, 03:54 AM
Hi,
I have a very long HTML code which I cannot understand what's going on. But I need to do a modification: I have a label <label id="current"></label> and the code stores some value in this label (list of words). When the user clicks on a button a new php page opens. In this new page I would like to reach the value of this label. How can do that?
Best,
-halit
PeejAvery
January 4th, 2010, 06:08 AM
The only way a new page can get that information is if the previous page passes it through GET or POST. This would be through a form, or even hard coded into the URL. Your best option is to pass it through the URL.
http://www.domain.com/page.php?list=one,two,three
Alternatively, you could use the PHP page to read the contents of the other and then parse the data. That would be a little bit more code. And, mostly likely a waste of time.
hkullana
January 7th, 2010, 04:41 PM
But the problem with labels is that they do not have a "name" attribute therefore I could not use GET and POST. Any suggestions how to use GET or POST to get the value of a label of the previous page?
PeejAvery
January 7th, 2010, 04:41 PM
You misunderstand my point...You will have to refer that information directly yourself.
hkullana
January 7th, 2010, 04:45 PM
Oh, sorry for that. But I could not understand what you mean since I am a newbie in html and php. Can you be more specific? Thank you very much
PeejAvery
January 7th, 2010, 04:57 PM
You will have to grab the labels yourself, using JavaScripts getElementById(), and pass that through GET or POST.
hkullana
January 7th, 2010, 05:05 PM
Ok: I followed these steps:
1) I have created a hidden input variable with the id = "h1" and name = "hidden" in HTML. And "l1" is the id of the label that I want to get the value in the new page.
2) Then I set a function called "set()" for the a button. So when the button is clicked the function will be called.
3) inside the function I did the following:
document.getElementById("h1").innerHTML = document.getElementById("l1").innerHTML;
Then I tried the get the value of hidden variable in the new page using its name ("hidden"). But it does not work?
PeejAvery
January 7th, 2010, 07:54 PM
You cannot use innerHTML for <input> tags because there is no HTML on the inner side. Example of innerHTML...<p> is innerHTML of <div>.
<div><p></p></div>
The <input> tag only has properties. You want...
document.getElementById("h1").value...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.