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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. shortcut key for current date in textbox

shortcut key for current date in textbox

Scheduled Pinned Locked Moved ASP.NET
csharpasp-nettutorialquestion
12 Posts 3 Posters 3 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.
  • J Offline
    J Offline
    janetb99
    wrote on last edited by
    #1

    I've got multiple date fields on a form in asp.net. I've been asked if there's a way to have a shortcut key (e.g. Ctl+semicolon) to fill the field with the current date. But, I don't want the fields to default to the current date, because many times the fields are left empty. Anybody got an example of code without buying Beans or some other outside software? Thanks, JB

    Y N 2 Replies Last reply
    0
    • J janetb99

      I've got multiple date fields on a form in asp.net. I've been asked if there's a way to have a shortcut key (e.g. Ctl+semicolon) to fill the field with the current date. But, I don't want the fields to default to the current date, because many times the fields are left empty. Anybody got an example of code without buying Beans or some other outside software? Thanks, JB

      Y Offline
      Y Offline
      Yusuf
      wrote on last edited by
      #2

      One way to implement is using jquery. check Javascript jQuery Hotkeys Plugin[^]

      Yusuf May I help you?

      J 1 Reply Last reply
      0
      • Y Yusuf

        One way to implement is using jquery. check Javascript jQuery Hotkeys Plugin[^]

        Yusuf May I help you?

        J Offline
        J Offline
        janetb99
        wrote on last edited by
        #3

        Thanks, Yusef, I'll take a look. The url supplied was a "not found" - maybe a typo? Could you redo, please? Thanks!

        Y 1 Reply Last reply
        0
        • J janetb99

          Thanks, Yusef, I'll take a look. The url supplied was a "not found" - maybe a typo? Could you redo, please? Thanks!

          Y Offline
          Y Offline
          Yusuf
          wrote on last edited by
          #4

          my bad, try this instead http://api.jquery.com/keypress/[^]

          Yusuf May I help you?

          J 1 Reply Last reply
          0
          • J janetb99

            I've got multiple date fields on a form in asp.net. I've been asked if there's a way to have a shortcut key (e.g. Ctl+semicolon) to fill the field with the current date. But, I don't want the fields to default to the current date, because many times the fields are left empty. Anybody got an example of code without buying Beans or some other outside software? Thanks, JB

            N Offline
            N Offline
            NeverHeardOfMe
            wrote on last edited by
            #5

            Does it have to be a shortcut key? That would be a little tricky to set up in a way that is truly cross-browser, cross-OS compatible, but it would be pretty easy to have a clickable image (or text) next to each box that would do this using JavaScript.

            J 1 Reply Last reply
            0
            • Y Yusuf

              my bad, try this instead http://api.jquery.com/keypress/[^]

              Yusuf May I help you?

              J Offline
              J Offline
              janetb99
              wrote on last edited by
              #6

              Thanks Yusef - looks like it might be putting me on the right track. Appreciate your time.

              1 Reply Last reply
              0
              • N NeverHeardOfMe

                Does it have to be a shortcut key? That would be a little tricky to set up in a way that is truly cross-browser, cross-OS compatible, but it would be pretty easy to have a clickable image (or text) next to each box that would do this using JavaScript.

                J Offline
                J Offline
                janetb99
                wrote on last edited by
                #7

                Interesting idea. Got an example anywhere? Might be a good idea.

                N 1 Reply Last reply
                0
                • J janetb99

                  Interesting idea. Got an example anywhere? Might be a good idea.

                  N Offline
                  N Offline
                  NeverHeardOfMe
                  wrote on last edited by
                  #8

                  well, use a JS function such as: function setNow(txt) { var d = new Date(); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var curr_year = d.getFullYear(); document.getElementById(txt).value = curr_date + "-" + curr_month + "-" + curr_year; } and then call it from whatever textboxes you want like this: today

                  J 1 Reply Last reply
                  0
                  • N NeverHeardOfMe

                    well, use a JS function such as: function setNow(txt) { var d = new Date(); var curr_date = d.getDate(); var curr_month = d.getMonth(); curr_month++; var curr_year = d.getFullYear(); document.getElementById(txt).value = curr_date + "-" + curr_month + "-" + curr_year; } and then call it from whatever textboxes you want like this: today

                    J Offline
                    J Offline
                    janetb99
                    wrote on last edited by
                    #9

                    Thanks, NeverHeardOfMe. Doesn't work for me to only use javascript and change my textboxes to non-asp.net textboxes. I'm going to have multiple date asp.net textboxes on the page, and within any of the textboxes, I need to be able to call the shortcut to render the current date, so if they could be asp.net textboxes, your code would work. But, I need the functionality of the asp.net textbox. I tried to get the text of the asp.net textbox to be a hyperlink, but it renders the text literally today. If I could get around that, it'd be wondermous. Any ideas?

                    J 1 Reply Last reply
                    0
                    • J janetb99

                      Thanks, NeverHeardOfMe. Doesn't work for me to only use javascript and change my textboxes to non-asp.net textboxes. I'm going to have multiple date asp.net textboxes on the page, and within any of the textboxes, I need to be able to call the shortcut to render the current date, so if they could be asp.net textboxes, your code would work. But, I need the functionality of the asp.net textbox. I tried to get the text of the asp.net textbox to be a hyperlink, but it renders the text literally today. If I could get around that, it'd be wondermous. Any ideas?

                      J Offline
                      J Offline
                      janetb99
                      wrote on last edited by
                      #10

                      NeverHeardOfMe - found it! This works: Thanks so much for pointing me in the right direction.

                      J 1 Reply Last reply
                      0
                      • J janetb99

                        NeverHeardOfMe - found it! This works: Thanks so much for pointing me in the right direction.

                        J Offline
                        J Offline
                        janetb99
                        wrote on last edited by
                        #11

                        Well, posh. Almost there. The textboxes are actually in a gridview, footer and edit rows. So, I tried this in the textbox on the footer row as a test: onClick="setNow(this);" and it didn't work. So I tried putting name="textBoxName" as well as id="textBoxName" on the control. Didn't work. Know of a way around this so that the javascript can get the correct argument? Thanks.

                        N 1 Reply Last reply
                        0
                        • J janetb99

                          Well, posh. Almost there. The textboxes are actually in a gridview, footer and edit rows. So, I tried this in the textbox on the footer row as a test: onClick="setNow(this);" and it didn't work. So I tried putting name="textBoxName" as well as id="textBoxName" on the control. Didn't work. Know of a way around this so that the javascript can get the correct argument? Thanks.

                          N Offline
                          N Offline
                          NeverHeardOfMe
                          wrote on last edited by
                          #12

                          You need to do it all in the RowDataBound event - find the textbox and use its ClientID property as the argument for your function call - which you will also have to build dynamivally in the same place.

                          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