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

TOPIC: Question condition with javascript

Question condition with javascript 3 years 3 weeks ago #95612

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
Hello folks,

I´m back with a brand new question :D.

So i´ve been struggeling with an AJAX - call in Limesurvey. Now after i´ve made it , there´s a new problem coming up :/

Is it possible to set the condition for the next question to the answer of my ajax call ? I mean if the call works the next question will be shown. If theres an error the next question should not be shown.

Is this possible ?
The administrator has disabled public write access.

Question condition with javascript 3 years 3 weeks ago #95617

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
It would probably be easiest to use the "success" setting of the AJAX call to toggle a hidden question. The hidden question could then be used for conditions/relevance for subsequent questions.

Can you attach your AJAX code and let us know what the possible returned data would be?
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.

Question condition with javascript 3 years 3 weeks ago #95620

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
This is just a Test , so the code isn´t finished .

<script src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><script>

function myCall() {
var request = $.ajax({
url: "ajax.php",
type: "GET",
dataType: "html"
});

request.done(function(jqXHR, textStatus) {
alert( "Request succeded " + textStatus );
});

request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
}
The administrator has disabled public write access.

Question condition with javascript 3 years 3 weeks ago #95636

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
Okay, so depending on what the PHP script returns, the call could be something like this:
$.ajax({
	url: 'ajax.php',
	dataType: 'html',
	data: {var1: 1}, // Data passed to the PHP function
	success: function(results){
		if(results = 1) {
			$('#question123 input.radio:first').click();
		}
		else {
			$('#question123 input.radio:last').click();
		}
	},
	error: function(){
		alert('Fail!');
	}
});
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: king_and1

Question condition with javascript 3 years 2 weeks ago #95739

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
Thanks for this reply, it´s very helpful. But how do i target the hidden Question ? For Example my hidden Question got the "QID 92" so should i just replace the "#question123" with the ID ?
The administrator has disabled public write access.

Question condition with javascript 3 years 2 weeks ago #95744

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
"#question123" would become "#question92".

Or, you can do this:
var qID = 92;
 
$.ajax({
	url: 'ajax.php',
	dataType: 'html',
	data: {var1: 1}, // Data passed to the PHP function
	success: function(results){
		if(results = 1) {
			$('#question'+qID+' input.radio:first').click();
		}
		else {
			$('#question'+qID+' input.radio:last').click();
		}
	},
	error: function(){
		alert('Fail!');
	}
});
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.

Question condition with javascript 3 years 1 week ago #95903

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
Can you help me Change the succes function. So it´s not depending on the result it gets but only if it works or not. So if the Call works it just should answer the hiden question with the first radio input. And if not the second one.

I also would like to know if the code "input.radio:first" is complete ? Isn´t there somethink like Q_A1 or so ?

Hope you can help me another time ^^
Thx for youre help anyway
The administrator has disabled public write access.

Question condition with javascript 3 years 1 week ago #95906

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
Can you help me Change the succes function. So it´s not depending on the result it gets but only if it works or not.
The success function gets fired if the request succeeds, so it will occur if the AJAX call found the PHP file, regardless of any results passed back from that file.

If you don't care about results, the call would look something like:
var qID = 92;
 
$.ajax({
	url: 'ajax.php',
	dataType: 'html',
	data: {var1: 1}, // Data passed to the PHP function
	success: function(results){
		$('#question'+qID+' input.radio:first').click();
	},
	error: function(){
		alert('Fail!');
	}
});

I also would like to know if the code "input.radio:first" is complete ?
Yes, the selector below is complete. It points to the first radio found in a question with an ID defined by "qID".
$('#question'+qID+' input.radio:first')
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.

Question condition with javascript 3 years 1 week ago #95911

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
<script src="ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script><script>
function myCall() {
var request = $.ajax({
url: "http://10.1...../lime/ajax.php",
type: "GET",
dataType: "html"
data: {var1: 1},
});

request.done(function(results) {
$("question91 input.radio:first").click();
});

request.fail(function(jqXHR, textStatus) {
alert( "Request failed: " + textStatus );
});
};
</script><input onclick="myCall()" type="button" value="Check" />






Thats my code now , but nothink happens .... No error and no questions are showing up -.-'
The administrator has disabled public write access.

Question condition with javascript 3 years 1 week ago #95914

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
You have a couple of syntax errors in the AJAX call and are missing a "#" in the selector. Also, you do not need to call jQuery - it is already included with LimeSurvey.
<script type="text/javascript" charset="utf-8">
	function myCall() {
		var request = $.ajax({
			url: "http://10.1...../lime/ajax.php",
			type: "GET",
			dataType: "html",
			data: {var1: 1}
		});
 
		request.done(function(results) {
			$("#question91 input.radio:first").click();
		});
 
		request.fail(function(jqXHR, textStatus) {
			alert( "Request failed: " + textStatus );
		});
	};
</script>
 
<input onclick="myCall()" type="button" value="Check" />
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.

Question condition with javascript 3 years 1 week ago #95915

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
I copied you´re code , and edi the url. But still nothink happens....

It doesn´t give me an error, so it finds the ajax.php i think and it runs. But it just can´t answer the question i think?

I´ve made a simple question with nothink in it.
I set the display setting to never or hiden i dont know
and the next question should open up if the hidden question answers right.

But nothink .... :(
The administrator has disabled public write access.

Question condition with javascript 3 years 1 week ago #95926

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5881
  • Thank you received: 1285
  • Karma: 518
Maybe the question ID is wrong?

Can you activate a test survey?
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.

Question condition with javascript 3 years 1 week ago #95927

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
I´ve checked the ID but it´s the right one....

And don´t really know how to activate a test survey
The administrator has disabled public write access.

Question condition with javascript 3 years 1 week ago #95946

  • Mazi
  • Mazi's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 5964
  • Thank you received: 363
  • Karma: 259
king_and1 wrote:
I´ve checked the ID but it´s the right one....

And don´t really know how to activate a test survey
Just activate your survey so we can access it and post the link to the survey here.

Best regards/Beste Grüße,
Dr. Marcel Minke
(Limesurvey Head of Support)
Need Help? We offer professional Limesurvey support
Contact: marcel.minke(at)limesurvey.org'"
The administrator has disabled public write access.

Question condition with javascript 3 years 1 week ago #96003

  • king_and1
  • king_and1's Avatar
  • Offline
  • Junior Lime
  • Posts: 29
  • Karma: 0
Ok , but i would have to copy it down to another server , gonna do this today.

But maybe there´s somethink more I need to do ?

In the IRC Live Chat someone once rode me that what i want to do is really tricky and I would have to edit this action also in the core of limesurvey not only via source on a special question. So what do you think about that ? Is that a possible reason ?
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.324 seconds