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. SharePoint
  4. Inserting a date when radio button is checked

Inserting a date when radio button is checked

Scheduled Pinned Locked Moved SharePoint
helpjavascripthtmlsharepointcom
7 Posts 3 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.
  • N Offline
    N Offline
    napy2
    wrote on last edited by
    #1

    Hello I hope someone can help me with the following problem. I have a form in sharepoint that has a number of items in it that includes checkboxes, drop down lists and text fields etc. One of these fields called Status has three radio buttons in it labelled New, In progress and Closed. The field below this is called Date Closed and has a text field next to it using a Date and Time control type (this gives a small calender button next to the text field where people can click to choose the date). I would like to know whether it is possible to enter the current date into the text field when the "Closed" radio button is clicked. In other words, it automatically populates the date in the text field when the user clicks the Closed radio button. I suppose removing the date if the user changes back to the "In progress" field would be useful too. I have tried editing the page in question using sharepoint designer and am able to inject the code I was trying to use to do this into the EditForm.aspx page (the page is a form in a sharepoint list). The code does appear in the page when loaded in the web browser but it doesn't seem to run correctly. Unfortunately I don't have enough knowledge of Javascript to work out why it won't execute correctly. The code is basically an edit of http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx I've copied the HTML the site generates for the radio buttons below hoping this will help with the naming of the fields:

    <span class="ms-RadioText" title="New"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00">New</label></span></td>
    </tr><tr>
    <td><span class="ms-RadioText" title="In progress"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" checked="checked" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01">In progress</label></span></td>
    </tr><tr>
    <td><

    N S 2 Replies Last reply
    0
    • N napy2

      Hello I hope someone can help me with the following problem. I have a form in sharepoint that has a number of items in it that includes checkboxes, drop down lists and text fields etc. One of these fields called Status has three radio buttons in it labelled New, In progress and Closed. The field below this is called Date Closed and has a text field next to it using a Date and Time control type (this gives a small calender button next to the text field where people can click to choose the date). I would like to know whether it is possible to enter the current date into the text field when the "Closed" radio button is clicked. In other words, it automatically populates the date in the text field when the user clicks the Closed radio button. I suppose removing the date if the user changes back to the "In progress" field would be useful too. I have tried editing the page in question using sharepoint designer and am able to inject the code I was trying to use to do this into the EditForm.aspx page (the page is a form in a sharepoint list). The code does appear in the page when loaded in the web browser but it doesn't seem to run correctly. Unfortunately I don't have enough knowledge of Javascript to work out why it won't execute correctly. The code is basically an edit of http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx I've copied the HTML the site generates for the radio buttons below hoping this will help with the naming of the fields:

      <span class="ms-RadioText" title="New"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00">New</label></span></td>
      </tr><tr>
      <td><span class="ms-RadioText" title="In progress"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" checked="checked" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01">In progress</label></span></td>
      </tr><tr>
      <td><

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      What does your JavaScript look like? Have you tried debugging it?


      I know the language. I've read a book. - _Madmatt

      N 1 Reply Last reply
      0
      • N Not Active

        What does your JavaScript look like? Have you tried debugging it?


        I know the language. I've read a book. - _Madmatt

        N Offline
        N Offline
        napy2
        wrote on last edited by
        #3

        Hi Mark Thanks for replying. The code is basically an edit of what one of the sharepoint developers posted on the MSDN blog here: http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx That code doesn't target radio buttons/text fields specifically which is what I'm after though I'm not sure what exactly I would need to change in it to make it so when a specific radio button is clicked it changes another field to be todays date. I can make the code in the link above execute on specific pages such as new forms or when editing current forms but I don't have enough knowledge of javascript to know how to target the specific radio button and text field present in the form. I'm pretty sure I need to modify the code to somehow reference the "closed" button using the id, name and input type tags in the HTML though I'm not sure what I have to do in order to get the onClick event to appear for the radio button neither am I sure on the javascript needed to make all this happen :( Thank you The code from the MSDN blog is:

        <script type="text/javascript">

        // This javascript sets the default value of a lookup field identified
        
        // by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
        
        // identified by <<QUERYSTRING VARIABLE NAME>>
        
         
        
         
        
        // Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
        
        // <<QUERYSTRING VARIABLE NAME>> with appropriate values.
        
        // Then just paste it into NewForm.aspx inside PlaceHolderMain
        
         
        
        \_spBodyOnLoadFunctionNames.push("fillDefaultValues");
        
         
        
        function fillDefaultValues() {
        
          var qs = location.search.substring(1, location.search.length);
        
          var args = qs.split("&");
        
          var vals = new Object();
        
          for (var i=0; i < args.length; i++) {
        
            var nameVal = args\[i\].split("=");
        
            var temp = unescape(nameVal\[1\]).split('+');
        
            nameVal\[1\] = temp.join(' ');
        
            vals\[nameVal\[0\]\] = nameVal\[1\];
        
          } 
        
          setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals\["<<QUERYSTRING VARIABLE NAME>>"\]);
        
        }
        
         
        
        function setLookupFromFieldName(fieldName, value) {
        
          if (value == undefined) return;
        
          var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
        
         
        
        // if theSelect is null, it means that the target l
        
        N 1 Reply Last reply
        0
        • N napy2

          Hi Mark Thanks for replying. The code is basically an edit of what one of the sharepoint developers posted on the MSDN blog here: http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx That code doesn't target radio buttons/text fields specifically which is what I'm after though I'm not sure what exactly I would need to change in it to make it so when a specific radio button is clicked it changes another field to be todays date. I can make the code in the link above execute on specific pages such as new forms or when editing current forms but I don't have enough knowledge of javascript to know how to target the specific radio button and text field present in the form. I'm pretty sure I need to modify the code to somehow reference the "closed" button using the id, name and input type tags in the HTML though I'm not sure what I have to do in order to get the onClick event to appear for the radio button neither am I sure on the javascript needed to make all this happen :( Thank you The code from the MSDN blog is:

          <script type="text/javascript">

          // This javascript sets the default value of a lookup field identified
          
          // by <<FIELD DISPLAY NAME>> to the value stored in the querysting variable
          
          // identified by <<QUERYSTRING VARIABLE NAME>>
          
           
          
           
          
          // Customize this javascript by replacing <<FIELD DISPLAY NAME>> and
          
          // <<QUERYSTRING VARIABLE NAME>> with appropriate values.
          
          // Then just paste it into NewForm.aspx inside PlaceHolderMain
          
           
          
          \_spBodyOnLoadFunctionNames.push("fillDefaultValues");
          
           
          
          function fillDefaultValues() {
          
            var qs = location.search.substring(1, location.search.length);
          
            var args = qs.split("&");
          
            var vals = new Object();
          
            for (var i=0; i < args.length; i++) {
          
              var nameVal = args\[i\].split("=");
          
              var temp = unescape(nameVal\[1\]).split('+');
          
              nameVal\[1\] = temp.join(' ');
          
              vals\[nameVal\[0\]\] = nameVal\[1\];
          
            } 
          
            setLookupFromFieldName("<<FIELD DISPLAY NAME>>", vals\["<<QUERYSTRING VARIABLE NAME>>"\]);
          
          }
          
           
          
          function setLookupFromFieldName(fieldName, value) {
          
            if (value == undefined) return;
          
            var theSelect = getTagFromIdentifierAndTitle("select","Lookup",fieldName);
          
           
          
          // if theSelect is null, it means that the target l
          
          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          napy2 wrote:

          The code is basically an edit of what one of the sharepoint developers posted on the MSDN blog

          Yes, you said that already. BTW, it is customary when including a URL to provide a link.

          napy2 wrote:

          I don't have enough knowledge of javascript to know how

          So what are you asking for then? How much help do you expect if you don't understand the code to do it? Modifying the default SharePoint code is NOT recommended as it used by all forms in the site. You may not want or need the code in all cases.


          I know the language. I've read a book. - _Madmatt

          N 1 Reply Last reply
          0
          • N Not Active

            napy2 wrote:

            The code is basically an edit of what one of the sharepoint developers posted on the MSDN blog

            Yes, you said that already. BTW, it is customary when including a URL to provide a link.

            napy2 wrote:

            I don't have enough knowledge of javascript to know how

            So what are you asking for then? How much help do you expect if you don't understand the code to do it? Modifying the default SharePoint code is NOT recommended as it used by all forms in the site. You may not want or need the code in all cases.


            I know the language. I've read a book. - _Madmatt

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

            Mark Nischalke wrote:

            So what are you asking for then? How much help do you expect if you don't understand the code to do it?

            Well some help with the code would be great. I understand the basics of the javascript code posted in the blog but as to the statements needed to modify it sufficiently to make it do what I want it to do is another thing. I'm aware that modifying the default sharepoint code will modify all forms in the site (or more specifically all forms that use EditForms.aspx) and this is the behaviour I want. Thanks

            1 Reply Last reply
            0
            • N napy2

              Hello I hope someone can help me with the following problem. I have a form in sharepoint that has a number of items in it that includes checkboxes, drop down lists and text fields etc. One of these fields called Status has three radio buttons in it labelled New, In progress and Closed. The field below this is called Date Closed and has a text field next to it using a Date and Time control type (this gives a small calender button next to the text field where people can click to choose the date). I would like to know whether it is possible to enter the current date into the text field when the "Closed" radio button is clicked. In other words, it automatically populates the date in the text field when the user clicks the Closed radio button. I suppose removing the date if the user changes back to the "In progress" field would be useful too. I have tried editing the page in question using sharepoint designer and am able to inject the code I was trying to use to do this into the EditForm.aspx page (the page is a form in a sharepoint list). The code does appear in the page when loaded in the web browser but it doesn't seem to run correctly. Unfortunately I don't have enough knowledge of Javascript to work out why it won't execute correctly. The code is basically an edit of http://blogs.msdn.com/b/sharepointdesigner/archive/2007/06/13/using-javascript-to-manipulate-a-list-form-field.aspx I've copied the HTML the site generates for the radio buttons below hoping this will help with the naming of the fields:

              <span class="ms-RadioText" title="New"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl00" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl00">New</label></span></td>
              </tr><tr>
              <td><span class="ms-RadioText" title="In progress"><input id="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01" type="radio" name="ctl00$m$g_9bfbce10_a236_4f06_b0fb_d8e53e39be05$ctl00$ctl04$ctl26$ctl00$ctl00$ctl04$ctl00$RadioButtons" value="ctl01" checked="checked" /><label for="ctl00_m_g_9bfbce10_a236_4f06_b0fb_d8e53e39be05_ctl00_ctl04_ctl26_ctl00_ctl00_ctl04_ctl00_ctl01">In progress</label></span></td>
              </tr><tr>
              <td><

              S Offline
              S Offline
              SAM_India
              wrote on last edited by
              #6

              HI you can use visual webpart using visual studio to complete your task. you see siddiq-sharepoint2010.blogspot.com and see visual webpart video,Hope it helps you Thanks, MOHAMMAD SIDDIQALI.

              N 1 Reply Last reply
              0
              • S SAM_India

                HI you can use visual webpart using visual studio to complete your task. you see siddiq-sharepoint2010.blogspot.com and see visual webpart video,Hope it helps you Thanks, MOHAMMAD SIDDIQALI.

                N Offline
                N Offline
                napy2
                wrote on last edited by
                #7

                Hi I've managed to figure out how to do this by writing some Javascript that manipulates the radio button and amend the text field accordingly. Thanks for your help though :)

                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