Access JSP hidden Variable in Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sgogula
    New Member
    • Sep 2007
    • 1

    #1

    Access JSP hidden Variable in Script

    Hi,

    Could someone help me how to access a JSP hidden variable in Java Script?

    Here is my code:

    Code:
    <script type="text/javascript">
    var mnuItems = ["../../jsp/actions/items.do?action=itemAction&itemId=[B]hdnItem[/B]]
    </script>
    
    <input type=hidden id="hdnItem" name = "hdnItem" value="A565CG"
    I would like to know how to access a hidden variable hdnItem in java script variable.

    Thanks
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    You got me there brother, here's a discussion on something similar:
    [removed link]

    And here:

    [removed link]
    Last edited by acoder; Dec 24 '08, 08:22 AM. Reason: Removed links to competing forum

    Comment

    • JosAH
      Recognized Expert MVP
      • Mar 2007
      • 11453

      #3
      This is a Javascript question so I've moved the thread.

      kind regards,

      Jos (moderator)

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        In this case, you'd access the hidden form value using:
        Code:
        document.getElementById("hdnItem").value
        Just make sure it's after page load, otherwise the element will be undefined.

        Having said that, you could just use JSP to generate the required JavaScript.

        Comment

        • Rsmastermind
          New Member
          • Sep 2008
          • 93

          #5
          After running the page on server it will get converted in HTML right click and view source look at the Id of the hidden field which you want to use.Now with the same Id use it in the javascript programming .If you face any problem post it .

          Comment

          Working...