how do i get to the value of a hidden field???

Last post 07-09-2008 7:10 AM by lavan. 6 replies.

Sort Posts:

  • how do i get to the value of a hidden field???

    07-08-2008, 4:54 PM
    • Member
      113 point Member
    • bcweed966
    • Member since 11-27-2006, 2:40 AM
    • Posts 657

    I have a lttle app and i am trying to get to the value of ahiden field on the form thru javascript and i am not expert and much less.

    i have this

    function TryTest(str) {
    Objt = document.getElementById(
    "hid1");
    }

    i also tryed it like this:

    Objt = window.document.getElementById("hid1");

    and like that:

    Objt =  $find('hid1')

    but i cant seem to be able to get a Value property from my objt object in my code. What is wrong. Is it because i installed AJAX toolkit?

  • Re: how do i get to the value of a hidden field???

    07-08-2008, 5:15 PM
    Answer

    document.getElementById("hid1").value

     

    Regards Mike
    [MVP - ASP/ASP.NET]
    My site    Please help - URGENT!!!    What ASP.NET can and can't do
  • Re: how do i get to the value of a hidden field???

    07-08-2008, 5:17 PM
    • All-Star
      25,424 point All-Star
    • budugu
    • Member since 01-12-2006, 2:15 PM
    • North Carolina
    • Posts 3,787

    If you are using HTML hidden field like this..

     

       <input id="hiddenText" type="hidden" name="hiddenText" runat="server" />

     you can access it by that ID..like

    var parameters= window.document.forms[0].hiddenText.value;

     

    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: how do i get to the value of a hidden field???

    07-08-2008, 5:21 PM
    • Member
      113 point Member
    • bcweed966
    • Member since 11-27-2006, 2:40 AM
    • Posts 657

    Thank you but I am using Asp:hiddenfield control

    <asp:HiddenField ID="hid1" Value="test" runat="server" />

     

  • Re: how do i get to the value of a hidden field???

    07-08-2008, 6:42 PM
    Answer
    • All-Star
      25,424 point All-Star
    • budugu
    • Member since 01-12-2006, 2:15 PM
    • North Carolina
    • Posts 3,787

    then it is ..

     

    var textvalue = document.getElementById("hid1").value;
    
     
    Vijay Kodali || My Blog


    "Don't be afraid to be wrong; otherwise you'll never be right."
  • Re: how do i get to the value of a hidden field???

    07-08-2008, 10:15 PM
    Answer
    • Contributor
      5,089 point Contributor
    • NHOQUE
    • Member since 04-02-2008, 9:00 AM
    • Kumamoto, Japan
    • Posts 849

    Try this,

     

    <script type="text/javascript">
    function findme()
    {
        var myhiddenvalue=document.getElementById('<%=hid1.ClientID %>').value;
        alert(myhiddenvalue);
    }
    
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>Finding Hidden Field Value</title>
    </head>
    <body onload="findme()">
        <form id="form1" runat="server">
        <div>
        <asp:HiddenField ID="hid1" Value="I am Hidden" runat="server" />
        </div>
        </form>
    </body>
    </html>
    

     The most important thing is

     var myhiddenvalue=document.getElementById('<%=hid1.ClientID %>').value;

    as <asp:HiddenField > is a server control.

     

    Thanks.

    HOQUE MD.NAZMUL
    [document.getReaders]
  • Re: how do i get to the value of a hidden field???

    07-09-2008, 7:10 AM
    Answer
    • Participant
      927 point Participant
    • lavan
    • Member since 11-01-2007, 7:01 AM
    • India
    • Posts 171
    Hi bcweed
    Change your script code like this to get the hiden value..

    function getHidVal()
    {
           hidval = document.getElementById("hid1").value;
          alert(hidval )
    }

    Hope this helps you..


    You can't do everything...
    But you can do something...
    So never refuse to do something that you can.....
Page 1 of 1 (7 items)