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

TOPIC: pre-fill textfield

pre-fill textfield 3 years 3 months 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.

Re: pre-fill textfield 3 years 3 months ago #63101

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6429
  • Thank you received: 840
  • Karma: 249
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.
The administrator has disabled public write access.

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

Re: Aw: pre-fill textfield 3 years 3 months ago #63130

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6429
  • Thank you received: 840
  • Karma: 249
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
The administrator has disabled public write access.

Aw: pre-fill textfield 3 years 3 months 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.

Re: Aw: pre-fill textfield 3 years 3 months ago #63157

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4269
  • Thank you received: 803
  • Karma: 368
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: claudio123

Re: Aw: pre-fill textfield 3 years 3 months 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.

Re: Aw: pre-fill textfield 3 years 3 months ago #63164

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4269
  • Thank you received: 803
  • Karma: 368
:) - 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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.
The following user(s) said Thank You: DenisChenu

Re: Aw: pre-fill textfield 3 years 3 months ago #63170

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

Tks
The administrator has disabled public write access.

Re: pre-fill textfield 3 years 3 months 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: 3 years 3 months ago by claudio123.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.190 seconds
Donation Image