Survey Forums

HomeHomeSurvey Project ...Survey Project ...Using Survey & ...Using Survey & ...get current date function?get current date function?
Previous
 
Next
New Post
6/1/2010 1:30 AM
 

Hi:

I create an open text question with textbox for users to enter the current date. However, I would like to put the current date in that textbox automatically by default. Which function can I use that does that? And how can I do it?

Please advise

 

Thanks

 
New Post
6/3/2010 12:55 AM
 

 Hello,

You can try the following:

- Go to Question answer editor
- Edit answer settings
- Default text value*

*you can specify special values that will be replaced at runtime into the text value :

##yourquerystringvariablename##
@@yoursessionvariablename@@
&&yourcookievariablename&&
%%servervariablename%%

Try using one of these options to add the current date to the textbox.  Hope this helps.
 

 

 
New Post
8/2/2012 4:39 PM
 
I want to do the same as the OP. I am trying to put the current date in a text field. The problem is that when I enter the code ##SELECT GETDATE()## in the 'Default text value' field, it does not compile it properly. Now I may be doing something wrong obviously,so what is it?
 
New Post
8/3/2012 7:36 PM
 

EDITED: cause I realized I gave directions that would not work.

 

I think I may have solved it. I say "may" cause Im not near the server my survey project is on, mainly cause its that day of the week that the people at work send me off to home with the excuse of some tradition called "Week-End" and Im not allowed within 5Kms of the work place (anyone knows about that btw?). So all this is theoretical mostly.

We need to create a new answer type with the following JavaScript code (yes its not my code, Im merely using it, although I have customized it a bit.)

We need to add the following code in the body of the file that contains the 'aspnetForm':

<script>

/*Current date in form credit:
JavaScript Kit (www.javascriptkit.com)
Over 200+ free scripts here!
*/

var cd=new Date();

var day=cd.getDay();
if (day<10){day="0"+day;}

var month=cd.getMonth()+1;
if (month<10){month="0"+month;}

var year=cd.getFullYear();

//////EDIT below three variable to customize the format of the date. Change the values appropriately to the date format of your choice (i.e. EU, US, etc...)/////

var displayfirst=day;
var displaysecond=month;
var displaythird=year;

document.formname.cdate.value=displayfirst+"/"+displaysecond+"/"+displaythird;
</script>

 Now the "tricky" part so to speak is the:

 document.formname.currentdate.value=displayfirst+"/"+displaysecond+"/"+displaythird;

We change 'formname' into 'aspnetForm' (which is the actual name of the form generated by Survey Project).

'cdate' is the actual ID of  the field corresponding to the answer.

After we create the answer type, we go the the question in question and add an answer which is of the type corresponding to the above, and in the ID field we put the appropriate value.

 

I think thats it. If anyone is willing and able to check it out until monday to see if it works as intended, I would be very grateful.

 
New Post
8/5/2012 11:11 AM
 
Hello,

Thanks for sharing this information and for trying to find a working solution. I'm afraid there is one part where the suggested solution will not work which has to do with setting and using the Answer ID field.

The ID field that can be set when adding answers (Edit Answer Settings) can be used for reporting options. It's not used as the ID for the answer field in the asp.net form. Because of this you you cannot set the input field ID to cdate.

Another way to refer to the input field in the javascript would be through the name field, however you need to use wildcards to find the right reference. Name is set automatically to something like: SurveyControl$Question58$_as44651$_ai197_as44651$ctl01

I hope you will find the right way to handle it.

Note to all readers: related post/information Codeplex Discussions "How To calculate Age"

 
Previous
 
Next
HomeHomeSurvey Project ...Survey Project ...Using Survey & ...Using Survey & ...get current date function?get current date function?