I need to pass value frome textbox to hidden field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • startsmart
    New Member
    • Sep 2006
    • 3

    I need to pass value frome textbox to hidden field

    Hi
    This is first time to write and alse it is first time to show this site

    my problem is i need to pass value from any input type like text for example

    to hidden field
    I tried to make a function but it does not work


    function hdate(){
    var m,x,y,z;
    x=document.frm1 .s1.value;
    y=document.frm1 .s2.value;
    z=document.frm1 .s3.value;
    m=x+y+z;
    return m;
    }


    and i called it using that code

    <input type="hidden" name="hiddenFie ld" value="hdata()"/>

    thank you in advance
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You need to write the value of the hidden field from javascript something like

    Code:
    function hdate(){
      var m,x,y,z;
      x=document.frm1.s1.value;
      y=document.frm1.s2.value;
      z=document.frm1.s3.value;
      m=x+y+z;
    
      document.frm1.hiddenField.value = m;
    }
    The value attribute is text not javascript which is why what you wrote doesn't work. You will have to work out a good time to call this function, from the onClick handler of a button or the onSubmit handler of the form may be.

    Comment

    • startsmart
      New Member
      • Sep 2006
      • 3

      #3
      Thank you very much

      i will try it

      Comment

      • Mehboob Ali

        #4
        Passing value from Textbox to HiddenInputFiel d

        Hi,First
        <input type="hidden" id="myhidden" runat="server" />
        in ur .aspx or .ascx page

        suppose i had a textbox ,from which i want to initilize this hiddenInputFiel d,i will use the typical onBlur() event of the textbox,so when the focus is lost from Textbox i will save the data in hiddenfiled.
        <asp:TextBox ID="mytxt" onBlur="popfiel d()" runat="server" />

        my sample popfield() function will be like

        <script language="javas cript" type="text/javascript">

        function popfield()
        {
        document.getEle mentById('myhid den').value =
        $get('<%=mytxt. ClientID %>').value;
        //alert(cument.ge tElementById('m yhidden').value );
        }
        </script>

        Comment

        Working...