CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2007
    Posts
    44

    Getting the value of a Label in new page

    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

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting the value of a Label in new page

    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.

    Code:
    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2007
    Posts
    44

    Re: Getting the value of a Label in new page

    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?

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting the value of a Label in new page

    You misunderstand my point...You will have to refer that information directly yourself.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2007
    Posts
    44

    Re: Getting the value of a Label in new page

    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

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting the value of a Label in new page

    You will have to grab the labels yourself, using JavaScripts getElementById(), and pass that through GET or POST.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jun 2007
    Posts
    44

    Re: Getting the value of a Label in new page

    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:

    Code:
    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?

  8. #8
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting the value of a Label in new page

    You cannot use innerHTML for <input> tags because there is no HTML on the inner side. Example of innerHTML...<p> is innerHTML of <div>.

    Code:
    <div><p></p></div>
    The <input> tag only has properties. You want...

    Code:
    document.getElementById("h1").value...
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured