Willkommen, Gast
Benutzername: Passwort: Angemeldet bleiben:

THEMA: hide question with javascript - javascript if doesn't works

hide question with javascript - javascript if doesn't works 5 Monate 1 Woche her #101361

  • DWS
  • DWSs Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 47
  • Karma: 1
Hi,

I'm triyng to hide some subquestions on array depending on subquestions answered on same array.

I put this code on question help:
<script type="text/javascript" charset="utf-8">
 
$('tr[id="javatbd779749X51X1568A3"]').attr('hidden', 'hidden');
 
 
</script><br />
<script type="text/javascript" charset="utf-8">
var rp1="{INSERTANS:779749X51X1568A1}";
 
document.write ("A1 = " + rp1) ;
 
</script><br />
<script type="text/javascript" charset="utf-8">
var rp1="{INSERTANS:779749X51X1568A1}";
if (rp1 !="") $('tr[id="javatbd779749X51X1568A4"]').attr('hidden', 'hidden') ;
if (rp1 =="Sí") $('tr[id="javatbd779749X51X1568A5"]').attr('hidden', 'hidden') ;
if (rp1 =="") $('tr[id="javatbd779749X51X1568A6"]').attr('hidden', 'hidden') ;
 
document.write ("A1= " + rp1) ;
</script>

Any help?

You can try the survey here:

http://arnsurveys.no-ip.org/lstests/index.php/survey/index/sid/779749/newtest/Y/lang/es
Letzte Änderung: 5 Monate 1 Woche her von DenisChenu.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

hide question with javascript - javascript if doesn't works 5 Monate 1 Woche her #101382

  • DenisChenu
  • DenisChenus Avatar
  • ONLINE
  • Moderator Lime
  • Beiträge: 5844
  • Dank erhalten: 715
  • Karma: 222
Hi,

Some probelm in your conde:
There are 1 logic problem: at start the array is empty, then you need to update when user answers.
Look at jquery api : api.jquery.com : and use it a lot.
Use Expression Manager and not INSERTANS
document.write is a bad idea, because you can do it only when javascript is done : then you need to add some extra div.

Surely some error, but you can try something like this: (adding <span id="whatisA1"></span>)
$(document).ready(function(){
  $("#question{QID} #javatbd{SGQ}A1 input").click(function(){
    var rp1=$("#answer{SGQ}A1").val();
    $("#whatisA1").text(rp1);
    if (rp1 !="") {$('#javatbd{SGQ}A4+').hide();}
    else{$('#javatbd{SGQ}A4').show();}
  });
});
etc ....

And use a real javascript console (firebug is a great tools for firefox (and some other)).

Denis
Der Administrator hat öffentliche Schreibrechte deaktiviert.

hide question with javascript - javascript if doesn't works 5 Monate 6 Tage her #101555

  • DWS
  • DWSs Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 47
  • Karma: 1
Hi, sorry but I have been busy last days.

Thanks for your code, but I have the same problem, don't hide the question even if the question is checked. It seems that don't recognize the value entered on the If condition.

The document.write tags are only for bug, to see what are the checked values. Anyway, I don't undestand why and where have to use the <span id="whatisA1"></span> labels.

And I use the default firefox webmaster tools to check the code. It works ok, there are no errors.

Thanks.
Regards.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

hide question with javascript - javascript if doesn't works 5 Monate 5 Tage her #101574

  • DWS
  • DWSs Avatar
  • OFFLINE
  • Senior Lime
  • Beiträge: 47
  • Karma: 1
Same on this survey:

arnsurveys.no-ip.org/demos1/index.php?si...95&newtest=Y&lang=es

I managed to change max value on the slider for each subquestion:

<script type="text/javascript" charset="utf-8">
$('#slider-param-max-84895X20X217d1').attr( "value","45" );
$('#slider-param-max-84895X20X217d2').attr( "value","90" );
$('#slider-param-max-84895X20X217d5').attr( "value","10" );
$('#slider-param-stepping-84895X20X217d5').attr( "value","1" );
</script>

But I want to change the values if first question is checked:

<script type="text/javascript">
var rp3="{INSERTANS:84895X20X245}";
if (rp3=="Sí") $('#slider-param-max-84895X20X217d1').attr( "value","85" );
</script>

Again this code doesn't works.

Can you help me?

Thanks.
Regards.
Der Administrator hat öffentliche Schreibrechte deaktiviert.

hide question with javascript - javascript if doesn't works 5 Monate 5 Tage her #101577

  • tpartner
  • tpartners Avatar
  • OFFLINE
  • LimeSurvey Team
  • Beiträge: 3813
  • Dank erhalten: 683
  • Karma: 328
You should put all of your jQuery inside a $(document).ready(function(){} function.

If the questions are on the same page you will need to put a listener on the first question - search the forums for "listener".
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.
Der Administrator hat öffentliche Schreibrechte deaktiviert.
Moderatoren: ITEd
Ladezeit der Seite: 0.143 Sekunden
Donation Image