• Resolved Sportuojantys

    (@needfeed)


    Hello, it’s been long time we discussed here ??

    I want to create a simple calculator, where you click the button and you get the phrase of the day + picture of that phrase. I need the help of the CFF Master ??

    My results appear in HTML content field with name: fieldname5 with class:
    <div class=”result-here”></div>

    I added 5 images with ‘hide’ class in these fields: fieldname6; fieldname7; fieldname8; fieldname9; fieldname10.

    My function don’t work correctly with images, I think I don’t understand about the data type of the fieldname6; fieldname7; fieldname8; fieldname9; fieldname10. So the function is bad when I talk about images in it ??

    Now, only phrase appears and image don’t appear.
    The thing should be that only 1 random phrase appear and the image of that phrase appears with the phrase too. Other images remains hidden.

    My function looks like this:

    jQuery('#fbuilder').on('click', function() {
    (function() {
    var result = Math.floor(Math.random() * 5) + 1;

    var phrases = [
    "Phrase No. 1",
    "Phrase No. 2",
    "Phrase No. 3",
    "Phrase No. 4",
    "Phrase No. 5"
    ];

    var phrase = phrases[result - 1];
    jQuery('.result-here').html(phrase);

    fieldname6.style.display = 'none';
    fieldname7.style.display = 'none';
    fieldname8.style.display = 'none';
    fieldname9.style.display = 'none';
    fieldname10.style.display = 'none';

    if (result === 1) {
    fieldname6.style.display = 'block';
    } else if (result === 2) {
    fieldname7.style.display = 'block';
    } else if (result === 3) {
    fieldname8.style.display = 'block';
    } else if (result === 4) {
    fieldname9.style.display = 'block';
    } else if (result === 5) {
    fieldname10.style.display = 'block';
    }

    return result;
    })();
    });
Viewing 7 replies - 1 through 7 (of 7 total)
  • Plugin Author CodePeople2

    (@codepeople2)

    Hello @needfeed

    The fields’ names in the equations are not their tags. The plugin replaces them with the corresponding fields’ values. So, you cannot use pieces of code as

    fieldname6.style.display

    In this case, you must call the SHOWFIELD and HIDEFIELD operations in the “Managing Fields Operations” module, and include the |n modifier to the field’s name to tell the plugin you are referring to the field’s name directly instead of its value.

    So, the correct would be pieces of codes like these ones:


    HIDEFIELD(fieldname6|n);
    SHOWFIELD(fieldname6|n);

    For additional questions, please provide the link to the page that contains the form for checking its structure.

    Best regards.

    Thread Starter Sportuojantys

    (@needfeed)

    Hi, calcualtor is still not published, so I can’t show it, only 1 problem left.

    Your solution worked perfectly fine, thanks!

    Now the last little thing is that in the begging, until the button is clicked, the INTRO image (fieldname6) should be shown and after the click is made it should disappear and not show again, in instead of this image, new image and phrase is shown. I didn’t add the hide class to the INTRO image, but I added HIDEFIELD class to fieldname6 after the click, but it is still showing.
    Maybe you know the reason?

    Here is the code now:

    jQuery('#fbuilder').on('click', function() {
    (function() {
    var result = Math.floor(Math.random() * 78) + 1;

    var phrases = [
    "<strong>NAME1</strong><br>Description1.",
    "<strong>NAME2</strong><br>Description2.",
    // I will add all 78 phrases here, following the same structure
    ];

    var phrase = phrases[result - 1];
    jQuery('.result-here').html(phrase);

    HIDEFIELD('fieldname6|n');

    for (var i = 7; i <= 84; i++) {
    HIDEFIELD('fieldname' + i + '|n');
    }
    return result;
    })();
    });

    Plugin Author CodePeople2

    (@codepeople2)

    Hello,

    Where have you entered that code?

    Best regards.

    Thread Starter Sportuojantys

    (@needfeed)

    Code is entered in calculated value: fieldname1
    Results is in HTML content: fieldname5
    Images are in: fieldname6 – fieldname84
    I need to hide intro image fieldname6 after the click and show random image from fieldname7-84 (the code is not working only with hiding the intro image fieldname6)

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @needfeed

    If the code corresponds to the equation in a calculated field there is no reason to use:

    jQuery('#fbuilder').on('click', function() {...});

    Also, you should not use quotes in the piece of code:

     HIDEFIELD('fieldname6|n');

    The correct would be:

     HIDEFIELD(fieldname6|n);

    Finally, I don’t know your project, so, I’m not sure the reason why you need to hide 84 fields or use 84 fields:

    for (var i = 7; i <= 84; i++) {
    HIDEFIELD('fieldname' + i + '|n');
    }

    But, I’m pretty sure there is another way to create the form that requires fewer fields.

    Best regards.

    Thread Starter Sportuojantys

    (@needfeed)

    Thank you ??

    Thread Starter Sportuojantys

    (@needfeed)

    Thank you (dublicated message occured)

Viewing 7 replies - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.