Can we set a default value to radio button? - InfoPath Dev
in

InfoPath Dev

Can we set a default value to radio button?

Last post 07-14-2009 11:47 PM by Moni's. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 07-12-2009 11:08 PM

    Can we set a default value to radio button?

    Hi There,

    Can we set a default value to radio button, for example say I have a field start date which has date value say (10/7/2009), I want to set my radio button default value as 3+ days of this start date. say (13/7/2009).

     Thanks in advance. Its an urgent issue for my project.

     Thanks,

    Monisha

    Filed under:
  • 07-12-2009 11:23 PM In reply to

    Re: Can we set a default value to radio button?

     It doesn't seem like you can use a formula to set the values of radio buttons, but what you can do is give the radio buttons simple values (like 1, 2, 3), and then use rules to set the value in another field depending on which one is selected.  This should give you some more flexibility.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-13-2009 12:04 AM In reply to

    Re: Can we set a default value to radio button?

    Hi Jimmy,

     Thanks , this helps.. But What is the funstion which I need to set to make the date as 3+, As I said, If my start date is 13/7/2009 then the default End date should be 16/7/2009. How can I do that..

     We have 2 functions in date one is now() and the other is today() , how can I use it to make 3+.

    Please reply with your Answer. Thanks alot for the help.

    Regards,

    Monisha

    Filed under:
  • 07-13-2009 12:19 AM In reply to

    Re: Can we set a default value to radio button?

     If you don't mind limiting your forms to InfoPath 2007, you can use the handy addDays() function:

     addDays(today(), 3)

    If not, you can use code to generate and store the value in a field where you can reference it at any time.

    Which way do you prefer?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-13-2009 01:06 AM In reply to

    Re: Can we set a default value to radio button?

    I cannot use InfoPath 2007 right now, and I came to know about the function addDays in 2007.

    So, I have only one option to use code. Could you help me in this?

    Thanks

    Filed under:
  • 07-13-2009 07:29 PM In reply to

    Re: Can we set a default value to radio button?

     Please try the attached template, which uses JScript to store [current date + 3 days] in one of the form's field when the form loads.  To avoid cluttering the form's main data source, you may want to store the value in a secondary data source, though that would be a bit more complicated.  Here is the JScript I used, for those who are curious:

          // Get today's date
        var three_days_from_now = new Date();
        // add three days
        three_days_from_now.setDate(three_days_from_now.getDate() + 3);
       
        // Select the node where the value will be stored
        var targetNode = XDocument.DOM.selectSingleNode("/my:myFields/my:threeDaysFromNow");
       
        // If the node has a nil attribute it needs to be removed
        var nilAttribute = targetNode.getAttributeNode("xsi:nil");
        if(nilAttribute != null)
        {
            targetNode.removeAttributeNode(nilAttribute);
        }
       
        // Store the date in XML format YYYY-MM-DD, adding zeros where necessary
        targetNode.text = three_days_from_now.getFullYear() + '-' +
           zeroPad(three_days_from_now.getMonth() + 1, 2) + '-' + zeroPad(three_days_from_now.getDate(), 2);

     zeroPad is a simple function that I borrowed from http://sujithcjose.blogspot.com/2007/10/zero-padding-in-java-script-to-add.html. Please see that page to have a look at its implementation

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 07-14-2009 10:20 PM In reply to

    Re: Can we set a default value to radio button?

    Beautiful solution. I appreciate this. It works really fine for me. Thanks a lot.

    Regards,

    Monisha

     

  • 07-14-2009 11:47 PM In reply to

    Re: Can we set a default value to radio button?

    One more question, if the code has to read startdate value+3 and not the default currentdate+3, then how should the code go?

    Filed under:
Page 1 of 1 (8 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.