- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Add php or javascript code to display a http requested text.
- jjesusfilho
- Topic Author
- Offline
- New Member
Less
More
6 years 6 months ago - 6 years 6 months ago #159506
by jjesusfilho
Add php or javascript code to display a http requested text. was created by jjesusfilho
I have a html page with several paragraphs. I would like to add a new of these paragraphs every time someone starts a survey. Can I add a php code to a question to request these paragraphs based on the the number of the survey. I was thinking of something like this:
$html = file_get_html(' example.com ');
$body = $html->find('p[form_number]');
$html = file_get_html(' example.com ');
$body = $html->find('p[form_number]');
Last edit: 6 years 6 months ago by jjesusfilho.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
6 years 6 months ago - 6 years 6 months ago #159508
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Add php or javascript code to display a http requested text.
You cannot insert PHP into the question but, if the document to be loaded resides on the same server, you can use the jQuery load() method.
Something like this will insert the contents of an element with ID "remoteContentToLoad" from example.com into an element with ID "elementToBeLoaded" in your survey page.
Something like this will insert the contents of an element with ID "remoteContentToLoad" from example.com into an element with ID "elementToBeLoaded" in your survey page.
Code:
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { $('#elementToBeLoaded').load('http://example.com #remoteContentToLoad'); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 6 months ago by tpartner.
The following user(s) said Thank You: DenisChenu, jjesusfilho
The topic has been locked.
- jjesusfilho
- Topic Author
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
6 years 6 months ago - 6 years 6 months ago #159523
by jjesusfilho
Replied by jjesusfilho on topic Add php or javascript code to display a http requested text.
Hi @tpartner, thank you very much for the helpfull reply. Can I ask you a further question? What is the elementToBeLoaded, a html div element? How about the remoteContentToLoad?
If I understood right, I should do something like that:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
$('#div1').load(' example.com #text');
});
</script>
But this is not working, which means I did not understand. Sorry I am not familiar with jquery load.
If I understood right, I should do something like that:
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:complete',function() {
$('#div1').load(' example.com #text');
});
</script>
But this is not working, which means I did not understand. Sorry I am not familiar with jquery load.
Last edit: 6 years 6 months ago by jjesusfilho.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10103
- Thank you received: 3591
6 years 6 months ago - 6 years 6 months ago #159537
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Add php or javascript code to display a http requested text.
The "elementToBeLoaded" is the ID of an element in your survey where you want to insert the dynamic text. So, assuming you want the dynamic text in a question, the source of that question might look something like this:
The "remoteContentToLoad" is the ID of an element in the remote HTML page that contains the text to be loaded. So, the source of the remote page (example.com) might look something like this:
Also remember that the remote HTML page must reside on the same server as the survey.
More on the jQuery load() method - api.jquery.com/load/
Code:
<!-- The static text --> <p>This is some static question text...</p> <!-- A container for the dynamic text --> <div id="elementToBeLoaded"></div> <!-- A script to insert the dynamic text --> <script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:complete',function() { $('#elementToBeLoaded').load('http://example.com #remoteContentToLoad'); }); </script>
The "remoteContentToLoad" is the ID of an element in the remote HTML page that contains the text to be loaded. So, the source of the remote page (example.com) might look something like this:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Dynamic Text</title> </head> <body> <div id="remoteContentToLoad"> This is the dynamic text that is to be loaded into the survey... </div> </body> </html>
Also remember that the remote HTML page must reside on the same server as the survey.
More on the jQuery load() method - api.jquery.com/load/
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 6 months ago by tpartner.
The topic has been locked.