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. ASP.NET
  4. Assign a value to a hidden field from javascript

Assign a value to a hidden field from javascript

Scheduled Pinned Locked Moved ASP.NET
javascripttutorial
13 Posts 5 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.
  • Y Offline
    Y Offline
    yesu prakash
    wrote on last edited by
    #1

    Hi, How to assign a value to a hidden field from javascript in page load. eg: I when a page load the screen resolution is taken from javascript and assign to a hidden field, and i need to do some work using the hiddenfield in code behind When i try the value is assign in javascript but in code behind it shown blank in hiddenfield Thankyou YPKI

    S J C A 4 Replies Last reply
    0
    • Y yesu prakash

      Hi, How to assign a value to a hidden field from javascript in page load. eg: I when a page load the screen resolution is taken from javascript and assign to a hidden field, and i need to do some work using the hiddenfield in code behind When i try the value is assign in javascript but in code behind it shown blank in hiddenfield Thankyou YPKI

      S Offline
      S Offline
      Sabari MD
      wrote on last edited by
      #2

      show your code first

      Sabari MD Application Developer Veloxit Info Solutions

      Y 1 Reply Last reply
      0
      • S Sabari MD

        show your code first

        Sabari MD Application Developer Veloxit Info Solutions

        Y Offline
        Y Offline
        yesu prakash
        wrote on last edited by
        #3

        function SetValue() { var width = screen.width; var height = screen.height; document.getElementById('hdnVal').value = width+'*'+height; } after i call the function window.onload = SetValue(); <script></x-turndown>

        S 2 Replies Last reply
        0
        • Y yesu prakash

          function SetValue() { var width = screen.width; var height = screen.height; document.getElementById('hdnVal').value = width+'*'+height; } after i call the function window.onload = SetValue(); <script></x-turndown>

          S Offline
          S Offline
          Sabari MD
          wrote on last edited by
          #4

          try by calling inside or inside

          Sabari MD Application Developer Veloxit Info Solutions

          1 Reply Last reply
          0
          • Y yesu prakash

            Hi, How to assign a value to a hidden field from javascript in page load. eg: I when a page load the screen resolution is taken from javascript and assign to a hidden field, and i need to do some work using the hiddenfield in code behind When i try the value is assign in javascript but in code behind it shown blank in hiddenfield Thankyou YPKI

            J Offline
            J Offline
            janani13
            wrote on last edited by
            #5

            print the value in alert and check whether it is called and its value.

            1 Reply Last reply
            0
            • Y yesu prakash

              function SetValue() { var width = screen.width; var height = screen.height; document.getElementById('hdnVal').value = width+'*'+height; } after i call the function window.onload = SetValue(); <script></x-turndown>

              S Offline
              S Offline
              Sabari MD
              wrote on last edited by
              #6

              function SetValue() { var width = screen.width; var height = screen.height; document.getElementById("hdnVal").value = width+"*"+height; } chk this

              Sabari MD Application Developer Veloxit Info Solutions

              1 Reply Last reply
              0
              • Y yesu prakash

                Hi, How to assign a value to a hidden field from javascript in page load. eg: I when a page load the screen resolution is taken from javascript and assign to a hidden field, and i need to do some work using the hiddenfield in code behind When i try the value is assign in javascript but in code behind it shown blank in hiddenfield Thankyou YPKI

                C Offline
                C Offline
                Christian Graus
                wrote on last edited by
                #7

                I suspect your issue is that you use the server side id of the control. You need to use the ClientID property of the control to work out the id you need to pass to the client to search for the control. You can also use Firebug in Firefox to step through your js and see what is happening.

                Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                Y 1 Reply Last reply
                0
                • C Christian Graus

                  I suspect your issue is that you use the server side id of the control. You need to use the ClientID property of the control to work out the id you need to pass to the client to search for the control. You can also use Firebug in Firefox to step through your js and see what is happening.

                  Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                  Y Offline
                  Y Offline
                  yesu prakash
                  wrote on last edited by
                  #8

                  When i give in alert, the value is displayed in alert box, but it is empty in code behind.

                  C 1 Reply Last reply
                  0
                  • Y yesu prakash

                    When i give in alert, the value is displayed in alert box, but it is empty in code behind.

                    C Offline
                    C Offline
                    Christian Graus
                    wrote on last edited by
                    #9

                    Well, your code sucks because it called getElementById and does not check that something was returned. Have you tried what I suggested ? Are you SURE you're using the right client side id ?

                    Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                    Y 1 Reply Last reply
                    0
                    • C Christian Graus

                      Well, your code sucks because it called getElementById and does not check that something was returned. Have you tried what I suggested ? Are you SURE you're using the right client side id ?

                      Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                      Y Offline
                      Y Offline
                      yesu prakash
                      wrote on last edited by
                      #10

                      contols i tried, and i try getElementById and getElementsByName also both giving right result in alert box, but blank in code behind. A javascrprt error:'Not Implemented' also

                      C 1 Reply Last reply
                      0
                      • Y yesu prakash

                        contols i tried, and i try getElementById and getElementsByName also both giving right result in alert box, but blank in code behind. A javascrprt error:'Not Implemented' also

                        C Offline
                        C Offline
                        Christian Graus
                        wrote on last edited by
                        #11

                        ypki wrote:

                        A javascrprt error:'Not Implemented' also

                        So there is your issue. Again, you need to pass the client id through in your script. Just like I told you in my first reply

                        Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                        Y 1 Reply Last reply
                        0
                        • C Christian Graus

                          ypki wrote:

                          A javascrprt error:'Not Implemented' also

                          So there is your issue. Again, you need to pass the client id through in your script. Just like I told you in my first reply

                          Christian Graus Driven to the arms of OSX by Vista. Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.

                          Y Offline
                          Y Offline
                          yesu prakash
                          wrote on last edited by
                          #12

                          how?

                          1 Reply Last reply
                          0
                          • Y yesu prakash

                            Hi, How to assign a value to a hidden field from javascript in page load. eg: I when a page load the screen resolution is taken from javascript and assign to a hidden field, and i need to do some work using the hiddenfield in code behind When i try the value is assign in javascript but in code behind it shown blank in hiddenfield Thankyou YPKI

                            A Offline
                            A Offline
                            Ajeet mittal
                            wrote on last edited by
                            #13

                            function SetValue() { var width = screen.width; var height = screen.height; document.getElementById('<%= hdnVal.ClientID %>').value = width+'*'+height; } use this function to set value in hiddenfield through javascript.

                            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