Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: pre-fill textfield

pre-fill textfield 5 years 1 month ago #63091

  • claudio123
  • claudio123's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Hello,
I'd like to have a pre-filled answer to a question, that can be changed or confirmed with enter or tab. I think I have seen this somewhere but have no idea where.
Thanks,
bes regards
claudio

I mean something like shown below using html:
<form action="textarea.htm">
<p>form:<br>
<textarea name="user_input" cols="50" rows="10">this is the pre-fill text.. </textarea>
</p>
</form>
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

pre-fill textfield 5 years 1 month ago #63101

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9298
  • Thank you received: 1330
  • Karma: 386
You can use some javascript,

Look at docs.limesurvey.org/tiki-index.php?page=...nswer_default_value_ for example.

Here,
<script>
$(document).ready(function() {
var QQ= 123 // put the right question number
$('#question'+QQ textarea.texarea).val('this is the pre-fill text.');
}
</script>

You can use sgqa or token attribute to prefill the answer.
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Aw: pre-fill textfield 5 years 1 month ago #63123

  • claudio123
  • claudio123's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Thanks Shnoulle,

I just tried your suggested code to have a simple date, time input to try it, but itz does not work, even with pre-defined text.
Do you have the time to have a look here?

thanks!
<script type="text/javascript" charset="utf-8">
//$(document).ready(function() {
 
   //var d=new Date();
   //var dat = d.toUTCString()+"<br>)";
var QQ = 383;
document.write(QQ);
//$('#question89794X7X383').val('"questiontext"');
$('#answer89794X7X383').val('"answertext"');
//$('#question'+QQ textarea.texarea).val('"textareatext"');
//}
</script>
<p>
	Date, Time</p>

I tried several different things as you can see....

best regards
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 5 years 1 month ago by claudio123.
The administrator has disabled public write access.

Aw: pre-fill textfield 5 years 1 month ago #63130

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9298
  • Thank you received: 1330
  • Karma: 386
I don't understand your script,

Look at :
docs.limesurvey.org/tiki-index.php?page=..._etc._in_LimeSurvey_

And add :
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
var QQ= 383 // put the right question number
$('#question'+QQ textarea.texarea).val('this is the pre-fill text.');
}
</script>

And only this (with XSS scripting protection desactivation)

After trye to find the good value for 'this is the pre-fill text.'.

And if you want more help, give a link to test what you done :).

Denis
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Aw: pre-fill textfield 5 years 1 month ago #63141

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

thanks, but... your script does not work for me. It looks like
var QQ= 383
is missing a ";" at the end of the line and
$('#question'+QQ textarea.texarea).val('this is the pre-fill text.');
is missing a "t" in texarea, but even if I add that the script does not work.

Very strange.

I have limnesurvey allowed XSS scripting and have other scripts doing well, but this one refuses.

Sorry, I have no server connected to the net, so I can't give a link.
Thanks,
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

Aw: pre-fill textfield 5 years 1 month ago #63157

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6207
  • Thank you received: 1375
  • Karma: 538
Try:
<script type="text/javascript" charset="utf-8">
 
	$(document).ready(function() {
		var QQ = 383; // put the right question number
		$('#question'+QQ+' textarea.texarea').val('this is the pre-fill text.'); 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
The following user(s) said Thank You: claudio123

Aw: pre-fill textfield 5 years 1 month ago #63161

  • claudio123
  • claudio123's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
Thanks Tony,
now all I had to add was the missing "t" in textarea.tex_area, now it works.
It was the missing ")" near the end of the scrtipt that stole hours from my lifetime.

Best regards
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
The administrator has disabled public write access.

Aw: pre-fill textfield 5 years 1 month ago #63164

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6207
  • Thank you received: 1375
  • Karma: 538
:) - Shnoulle and I have signed up for typing lessons.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu

Aw: pre-fill textfield 5 years 1 month ago #63170

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9298
  • Thank you received: 1330
  • Karma: 386
tpartner wrote:
:) - Shnoulle and I have signed up for typing lessons.
Oh yes, i had too ....

Tks
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

pre-fill textfield 5 years 1 month ago #63171

  • claudio123
  • claudio123's Avatar
  • Offline
  • Junior Lime
  • Posts: 31
  • Thank you received: 1
  • Karma: 0
- I think I will also sign up for some more lessons in detecting not opened or not closed brackets as well as understanding where they are needed...
Thanks,
best regards
Claudio

BTW: I discovered some strange behavior - the only way I could make the question perform the way I intended was using the following code pasted in the source of a question:
Datum, Zeit<br>
 <script type="text/javascript" charset="utf-8">
	 var Dat = new Date();
	 var min = Dat.getMinutes();
	 if (min <10)
	  {
	    min= "0" + String(min); // insert 0, if minutes are <10
	  }
	 var Dat = [Dat.getDate(), (Dat.getMonth() + 1), Dat.getFullYear(), Dat.getHours(), min];
	 var datzeit=Dat[0] + "." + Dat[1] + "." + Dat[2] + " - " + Dat[3] + ":" + Dat[4] + " Uhr";
 
	 document.write("Heute ist der "+datzeit);
 
	 $(document).ready(function() {
		var QQ = 383; // put the right question number
		$('#question'+QQ+' textarea.textarea').val(datzeit); 
		});
</script>

the strange thing is that
$(document).ready(function() {

must not cover the whole script, otherwise I only see the output of
document.write("Heute ist der "+datzeit);

Do you understand why?

Again thanks,
Claudio
... lost in brackets ...
(I suggest a preview option for posting in the forum)
Last Edit: 5 years 1 month ago by claudio123.
The administrator has disabled public write access.

pre-fill textfield 5 years 1 month ago #63183

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6207
  • Thank you received: 1375
  • Karma: 538
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.
The administrator has disabled public write access.

pre-fill textfield 5 years 1 month 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: 5 years 1 month ago by claudio123.
The administrator has disabled public write access.

pre-fill textfield 4 years 3 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.
Moderators: ITEd
Time to create page: 0.324 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form