Connect RichText element via Javascript

I have a RichText box connected to a database field via a dataset, however I am in the process of disconnecting everything from the dataset and connecting all elements via Javascript code.
I’m a bit stuck on the RichText box and am unsure on the code needed to connect this, can anyone help or point me in the right direction please.

I have tried…

$w(‘#richText’).text = productDescription;

Thanks

Are you able to share more of your code?

@ChrisH hey there - to set a Rich Text field to a text element, you may have to use the .html property instead of .text

The html property maps the Editor’s built-in text themes and custom formatting to HTML and CSS as described here.

To set or get the plain, unstyled contents of a text element, use the text property instead.

So your code should maybe look like this:

$w(‘#richText’).html = productDescription;

Hi

Full page code below…

I have tried adding ‘$w(‘#richText’).text = productDescription;’ & also ‘$w(‘#richText’).html = productDescription;’, so I must be missing something but unsure as to what, I am quite new to coding, thanks.

    $w.onReady(function () {
        $w("#MensFootwearItem").onReady(() => {
            let item = $w("#MensFootwearItem").getCurrentItem();

            $w('#imageX144').src = item.mainImage;
            $w('#imageX145').src = item.image1;
            $w('#imageX146').src = item.image2;
            $w('#imageX147').src = item.image3;
            $w('#text29').text = item.h1Title;
            $w('#text206').text = item.styleCode;
            $w('#text203').text = item.price;

            $w('#text101').text = item.supplier1;
            $w('#text36').text = item.priceUrl1;
            $w('#text37').text = item.sizeText1;

            $w('#text42').text = item.supplier2;
            $w('#text41').text = item.priceUrl2;
            $w('#text40').text = item.sizeText2;

            $w('#text46').text = item.supplier3;
            $w('#text45').text = item.priceUrl3;
            $w('#text44').text = item.sizeText3;

            $w('#text50').text = item.supplier4;
            $w('#text49').text = item.priceUrl4;
            $w('#text48').text = item.sizeText4;

            $w('#text54').text = item.supplier5;
            $w('#text53').text = item.priceUrl5;
            $w('#text52').text = item.sizeText5;

            $w('#text281').text = item.supplier6;
            $w('#text280').text = item.priceUrl6;
            $w('#text279').text = item.sizeText6;

            $w('#text294').text = item.supplier7;
            $w('#text293').text = item.priceUrl7;
            $w('#text292').text = item.sizeText7;

            $w('#text297').text = item.supplier8;
            $w('#text296').text = item.priceUrl8;
            $w('#text295').text = item.sizeText8;

            if (item.supplier1) {
                $w("#box86, #imageX8, #buyNow1").show();
                $w('#imageX8').src = item.urlImage1;
            }
            if (item.sizeText1 === 'Sold Out') {
                $w('#buyNow1').style.backgroundColor = "#FF0000";
            }
            if (item.supplier2) {
                $w("#box85, #imageX14, #buyNow2, #line12").show();
                $w('#imageX14').src = item.urlImage2;
            } else {
                $w("#box85, #imageX14, #buyNow2, #line12").collapse();
            }
            if (item.sizeText2 === 'Sold Out') {
                $w('#buyNow2').style.backgroundColor = "#FF0000";
            }
            if (item.supplier3) {
                $w("#box34, #imageX10, #buyNow3, #line13").show();
                $w('#imageX10').src = item.urlImage3;
            } else {
                $w("#box34, #imageX10, #buyNow3, #line13").collapse();
            }
            if (item.sizeText3 === 'Sold Out') {
                $w('#buyNow3').style.backgroundColor = "#FF0000";
            }
            if (item.supplier4) {
                $w("#box35, #imageX12, #buyNow4, #line14").show();
                $w('#imageX12').src = item.urlImage4;
            } else {
                $w("#box35, #imageX12, #buyNow4, #line14").collapse();
            }
            if (item.sizeText4 === 'Sold Out') {
                $w('#buyNow4').style.backgroundColor = "#FF0000";
            }
            if (item.supplier5) {
                $w("#box36, #imageX13, #buyNow5, #line15").show();
                $w('#imageX13').src = item.urlImage5;
            } else {
                $w("#box36, #imageX13, #buyNow5, #line15").collapse();
            }
            if (item.sizeText5 === 'Sold Out') {
                $w('#buyNow5').style.backgroundColor = "#FF0000";
            }
            if (item.supplier6) {
                $w("#box373, #imageX141, #buyNow6, #line16").show();
                $w('#imageX141').src = item.urlImage6;
            } else {
                $w("#box373, #imageX141, #buyNow6, #line16").collapse();
            }
            if (item.sizeText6 === 'Sold Out') {
                $w('#buyNow6').style.backgroundColor = "#FF0000";
            }
            if (item.supplier7) {
                $w("#box415, #imageX142, #buyNow7, #line17").show();
                $w('#imageX142').src = item.urlImage7;
            } else {
                $w("#box415, #imageX142, #buyNow7, #line17").collapse();
            }
            if (item.sizeText7 === 'Sold Out') {
                $w('#buyNow7').style.backgroundColor = "#FF0000";
            }
            if (item.supplier8) {
                $w("#box416, #imageX143, #buyNow8, #line18").show();
                $w('#imageX143').src = item.urlImage8;
            } else {
                $w("#box416, #imageX143, #buyNow8, #line18").collapse();
            }
            if (item.sizeText8 === 'Sold Out') {
                $w('#buyNow8').style.backgroundColor = "#FF0000";
            }
        });
    });

    export function imageX144_viewportEnter(event) {
        $w('#box424').style.backgroundColor = "#000000";
    }

    export function imageX144_viewportLeave(event) {
        $w('#box424').style.backgroundColor = "#979797";
    }

    export function imageX145_viewportEnter(event) {
        $w('#box425').style.backgroundColor = "#000000";
    }

    export function imageX145_viewportLeave(event) {
        $w('#box425').style.backgroundColor = "#979797";
    }

    export function imageX146_viewportEnter(event) {
        $w('#box426').style.backgroundColor = "#000000";
    }

    export function imageX146_viewportLeave(event) {
        $w('#box426').style.backgroundColor = "#979797";
    }

    export function imageX147_viewportEnter(event) {
        $w('#box427').style.backgroundColor = "#000000";
    }

    export function imageX147_viewportLeave(event) {
        $w('#box427').style.backgroundColor = "#979797";
    }

I assume you’ve tried $w("#richText").html = item.productDescription - including item. before productDescription?

Yes, I have tried this and it does not work, the richText box does not populate with any content and it seems to remove the instructions for the other elements.