Support

Home Forums Event Espresso Premium Show and hide

Show and hide

Posted: November 24, 2016 at 2:05 am

Viewing 4 reply threads


kemst

November 24, 2016 at 2:05 am

Hi
I am trying to create a show and hide based on selection from a dropdown question.
see this post https://eventespresso.com/topic/dropdown-questions/#post-222019

Here is an event on my page https://kennslumidstod.hi.is/events/kenningar-um-ahugahvot-og-hagnytt-gildi-theirra-i-kennslustofunni/ and if you press “Skráning” you will be taken to the registration form.

I am trying to hide based on what you see in this picture http://imgur.com/a/3u737

This is the code I am using but I am getting errors

function ee_custom_show_question_conditionally() {
wp_add_inline_script(
‘ee_form_section_validation’,
jQuery(document).ready(function($) {
var text = $(“.ee-reg-qstn-17-input-dv”);
$(text).hide();
$(“.ee-reg-qstn-11”).change(function() {
$(this).val() == “Þverfræðilegt”
$(text).show() :
$(text).hide();
});
});’
);
}
add_action( ‘wp_enqueue_scripts’, ‘ee_custom_show_question_conditionally’, 11 );

Let me know if you see the error in the code. Thanks in advance Runar


Josh

  • Support Staff

November 25, 2016 at 9:25 am

Hi there,

It looks like there’s at least one error in your code. This part:

$(this).val() == "Þverfræðilegt"
$(text).show() :
$(text).hide();

Should be a ternary comparison, but it’s missing a ?. So it should look more like this:

$(this).val() == "Þverfræðilegt" ?
$(text).show() :
$(text).hide();


kemst

November 28, 2016 at 2:38 am

I get a SyntaxError when using this code. I got this code from you at this page https://gist.github.com/joshfeck/183209d5239cc07ec94f9ebbfb017d40

Regards,
Runar


Tony

  • Support Staff

November 28, 2016 at 6:27 am

The code Josh recommended works fine when I add it to console.

When the code is added – http://take.ms/Hc3cc

After selecting the correct value – http://take.ms/Hc3cc

I took the JS you from the code you linked above and added it directly to Chrome Dev Tools through the console.

The only changes made then was to the ID uses in the class names and the value to check for.

Double check the code you are using, confirm all of the punctuation is unstyled:

jQuery( document ).ready(function($) {
    var text = $(".ee-reg-qstn-17-input-dv");
    $(text).hide();
    $(".ee-reg-qstn-11").change(function() {
        $(this).val() == "Þverfræðilegt" ?
        $(text).show() :
        $(text).hide();
    });
});


kemst

November 29, 2016 at 1:40 am

Thank you so much Tony. I see that you also left out the final line. This works perfectly 🙂

Viewing 4 reply threads

The support post ‘Show and hide’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso