pre-fill textfield

More
5 years 10 months ago #63091 by claudio123
claudio123 created the topic: pre-fill textfield
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)

Please Log in to join the conversation.

More
5 years 10 months ago #63101 by DenisChenu
DenisChenu replied the topic: pre-fill textfield
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 development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #63123 by claudio123
claudio123 replied the topic: Aw: pre-fill textfield
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 10 months ago by claudio123.

Please Log in to join the conversation.

More
5 years 10 months ago #63130 by DenisChenu
DenisChenu replied the topic: Aw: pre-fill textfield
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 development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
5 years 10 months ago #63141 by claudio123
claudio123 replied the topic: Aw: pre-fill textfield
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)

Please Log in to join the conversation.

More
5 years 10 months ago #63157 by tpartner
tpartner replied the topic: Aw: pre-fill textfield
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 following user(s) said Thank You: claudio123

Please Log in to join the conversation.

More
5 years 10 months ago #63161 by claudio123
claudio123 replied the topic: Aw: pre-fill textfield
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)

Please Log in to join the conversation.

More
5 years 10 months ago #63164 by tpartner
tpartner replied the topic: Aw: pre-fill textfield
:) - 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 following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

More
5 years 10 months ago #63170 by DenisChenu
DenisChenu replied the topic: Aw: pre-fill textfield

tpartner wrote: :) - Shnoulle and I have signed up for typing lessons.

Oh yes, i had too ....

Tks

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #63171 by claudio123
claudio123 replied the topic: pre-fill textfield
- 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 10 months ago by claudio123.

Please Log in to join the conversation.

More
5 years 10 months ago #63183 by tpartner
tpartner replied the topic: pre-fill textfield
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.

Please Log in to join the conversation.

More
5 years 10 months ago - 5 years 10 months ago #63187 by claudio123
claudio123 replied the topic: pre-fill textfield
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 10 months ago by claudio123.

Please Log in to join the conversation.

More
5 years 3 weeks ago #79765 by audiolime
audiolime replied the topic: pre-fill textfield
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?

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now