Add php or javascript code to display a http requested text.

More
1 month 1 week ago - 1 month 1 week ago #159506 by jjesusfilho
jjesusfilho created the topic: Add php or javascript code to display a http requested text.
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]');
Last Edit: 1 month 1 week ago by jjesusfilho.

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #159508 by tpartner
tpartner replied the 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.

<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: 1 month 1 week ago by tpartner.
The following user(s) said Thank You: DenisChenu, jjesusfilho

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #159523 by jjesusfilho
jjesusfilho replied the 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.
Last Edit: 1 month 1 week ago by jjesusfilho.

Please Log in to join the conversation.

More
1 month 1 week ago - 1 month 1 week ago #159537 by tpartner
tpartner replied the 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 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:

<!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: 1 month 1 week ago by tpartner.

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!