Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: pre-fill textfield

Re: pre-fill textfield 3 years 4 months ago #63183

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4356
  • Thank you received: 826
  • Karma: 381
It's not a good idea to use "min" as a variable name because it refers to a JavaScript method. Also, I think you were redefining the variable "Dat".

Try this ( I assume you want to load the current date and time into the textarea in a readable format):
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
		var Dat = new Date();
		var minutes = Dat.getMinutes();
		if (minutes <10)
		{
			minutes= "0" + String(minutes); // insert 0, if minutes are <10
		}
		var DatArr = [Dat.getDate(), (Dat.getMonth() + 1), Dat.getFullYear(), Dat.getHours(), minutes];
		var datzeit=DatArr[0] + "." + DatArr[1] + "." + DatArr[2] + " - " + DatArr[3] + ":" + DatArr[4] + " Uhr";
 
		var QQ = 383; // put the right question number
		$('#question'+QQ+' textarea.textarea').val("Heute ist der "+datzeit); 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: pre-fill textfield 3 years 4 months ago #63187

  • claudio123
  • claudio123's Avatar
  • OFFLINE
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Tony,

redefining "dat" works well, using "min" as a variable also does the job, it is however confusing, I admit.

Another strange behavior I realized is that the textarea is only filled with the text I want to be displayed, if I define the number of rows of the textarea. If I do not define it, pre-fill text is not displayed. (Took me another hour to find that out...)

And I used the date as an example to pre-fill a text area - it can still be edited while filling the survey but offers the current data - this was just an idea.

AND: I want a preview for forum posts - it would prevent a lot of editing...
... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 3 years 4 months ago by claudio123.
The administrator has disabled public write access.

Re: pre-fill textfield 2 years 6 months ago #79765

  • audiolime
  • audiolime's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 17
  • Karma: 0
That's exactly what I am looking for!
How and where do I add the number of rows for the textarea - could you provide an example of the code you used in the end?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.116 seconds
Donation Image