Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. How to set the value of a hidden control??

How to set the value of a hidden control??

Scheduled Pinned Locked Moved Web Development
javascripthelptutorialquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Brendan Vogt
    wrote on last edited by
    #1

    Hi, I need to set the value of my hidden control. Up to this point I had just played around, have not created the full value of the hidden control. I just want to add the current local date, but that I will do. I just need to know how to set the value parameter from a value returned from a function. My hidden control: My javascript function: function GetDateTime() { var date = new Date(); // Year var year = date.getFullYear(); // Month var month = date.getMonth(); } Please can someone help me? Regards ma se

    V B 2 Replies Last reply
    0
    • B Brendan Vogt

      Hi, I need to set the value of my hidden control. Up to this point I had just played around, have not created the full value of the hidden control. I just want to add the current local date, but that I will do. I just need to know how to set the value parameter from a value returned from a function. My hidden control: My javascript function: function GetDateTime() { var date = new Date(); // Year var year = date.getFullYear(); // Month var month = date.getMonth(); } Please can someone help me? Regards ma se

      V Offline
      V Offline
      vimal_yet
      wrote on last edited by
      #2

      Try the following window.opener.document.forms("formname").elements("id (Example:hdnLocalDate) or name ").Value Regards, Vimal

      If U Get Errors U Will Learn If U Don't Get Errors U Have Learnt

      B 1 Reply Last reply
      0
      • B Brendan Vogt

        Hi, I need to set the value of my hidden control. Up to this point I had just played around, have not created the full value of the hidden control. I just want to add the current local date, but that I will do. I just need to know how to set the value parameter from a value returned from a function. My hidden control: My javascript function: function GetDateTime() { var date = new Date(); // Year var year = date.getFullYear(); // Month var month = date.getMonth(); } Please can someone help me? Regards ma se

        B Offline
        B Offline
        badgrs
        wrote on last edited by
        #3

        simply add a return statement to your function, that should work no?

           function GetDateTime()
           {
              var date = new Date();
        
              return date.toString("DD/MM/YYYY"); // you can use different date formats here
           }
        
        B 1 Reply Last reply
        0
        • V vimal_yet

          Try the following window.opener.document.forms("formname").elements("id (Example:hdnLocalDate) or name ").Value Regards, Vimal

          If U Get Errors U Will Learn If U Don't Get Errors U Have Learnt

          B Offline
          B Offline
          Brendan Vogt
          wrote on last edited by
          #4

          I want to set the value of the hidden control. When I do the following: Response.Write("hdnLocalDate = " + hdnLocalDate.Value); I get the value to be something like GetDateTime(). regards

          1 Reply Last reply
          0
          • B badgrs

            simply add a return statement to your function, that should work no?

               function GetDateTime()
               {
                  var date = new Date();
            
                  return date.toString("DD/MM/YYYY"); // you can use different date formats here
               }
            
            B Offline
            B Offline
            Brendan Vogt
            wrote on last edited by
            #5

            When I do a Response.Write on the hidden controls value like: Response.Write("hdnLocalDate = " + hdnLocalDate.Value); ..then it displays: hdnLocalDate = javascript:GetDateTime(); What now?? If I do a view code, must it display the value property's value as the date returned?

            B 1 Reply Last reply
            0
            • B Brendan Vogt

              When I do a Response.Write on the hidden controls value like: Response.Write("hdnLocalDate = " + hdnLocalDate.Value); ..then it displays: hdnLocalDate = javascript:GetDateTime(); What now?? If I do a view code, must it display the value property's value as the date returned?

              B Offline
              B Offline
              badgrs
              wrote on last edited by
              #6

              Hmm, good point, of course the value field will never run the javascript, just take it as a string literal....how silly of me :^) You'd have to run some function when the page loads to populate the hidden field. window.onload = function() { hdnLocalDate.value = new Date().toString("DD/MM/YYYY"); } Of course with runat="server" on the hidden form field its ID could easily change if its inside an INamingContainer.

              B 1 Reply Last reply
              0
              • B badgrs

                Hmm, good point, of course the value field will never run the javascript, just take it as a string literal....how silly of me :^) You'd have to run some function when the page loads to populate the hidden field. window.onload = function() { hdnLocalDate.value = new Date().toString("DD/MM/YYYY"); } Of course with runat="server" on the hidden form field its ID could easily change if its inside an INamingContainer.

                B Offline
                B Offline
                Brendan Vogt
                wrote on last edited by
                #7

                Does onload exist?? I typed in window. and then there was no onload option. I am using VS 2005. It's still not working: <!-- // Hide from old browsers window.onload = function() { hdnLocalDate.value = new Date().toString("DD/MM/YYYY"); } //-->

                B 1 Reply Last reply
                0
                • B Brendan Vogt

                  Does onload exist?? I typed in window. and then there was no onload option. I am using VS 2005. It's still not working: <!-- // Hide from old browsers window.onload = function() { hdnLocalDate.value = new Date().toString("DD/MM/YYYY"); } //-->

                  B Offline
                  B Offline
                  badgrs
                  wrote on last edited by
                  #8

                  ma se wrote:

                  Does onload exist?? I typed in window. and then there was no onload option. I am using VS 2005.

                  Javascript intellisense in practically non-existent in visual studio, personally I use Aptana for all my JS/CSS development. My fault again that it doesn't work, using ID.attribute won't work you need a reference to the DOM element via getElementById. Try this: <!-- // Hide from old browsers window.onload = function() { document.getElementById('<%= hdnLocalDate.ClientID %>').value = new Date().toString("DD/MM/YYYY"); } //-->

                  H 1 Reply Last reply
                  0
                  • B badgrs

                    ma se wrote:

                    Does onload exist?? I typed in window. and then there was no onload option. I am using VS 2005.

                    Javascript intellisense in practically non-existent in visual studio, personally I use Aptana for all my JS/CSS development. My fault again that it doesn't work, using ID.attribute won't work you need a reference to the DOM element via getElementById. Try this: <!-- // Hide from old browsers window.onload = function() { document.getElementById('<%= hdnLocalDate.ClientID %>').value = new Date().toString("DD/MM/YYYY"); } //-->

                    H Offline
                    H Offline
                    HarryIsp2007
                    wrote on last edited by
                    #9

                    /// this is the code final, i have just test; Untitled Page <!-- // Hide from old browsers window.onload = function() { var date=new Date(); document.getElementById('<%= hdnLocalDate.ClientID %>').value = date.toDateString();//set again value if you want. //--> }

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups