# Code error message when creating an expandable text box

**URL:** <https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 21, 2018, 2:27am UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374 "2018-05-21T02:27:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmkogos2](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@cmkogos2](https://forum.wixstudio.com/u/cmkogos2)\
**Post date:** [May 21, 2018, 2:27am UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/1 "2018-05-21T02:27:52Z")

</div>

Can anyone out there tell me why I get this error message when creating an expandable text box with a “show more” button: Wix code SDK error: The text parameter that is passed to the text method cannot be set to the value 40. It must be of type string.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [May 21, 2018, 5:15am UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/2 "2018-05-21T05:15:55Z")

</div>

Hi,

Without seeing your code it’s difficult to say for sure. Apparently you are trying to set the contents of the text box to a number and not to a text string.

Yisrael

---

<div class="post-metadata">

**Author:** ![cmkogos2](https://avatars.discourse-cdn.com/v4/letter/c/71c47a/32.png) [@cmkogos2](https://forum.wixstudio.com/u/cmkogos2)\
**Post date:** [May 21, 2018, 5:39pm UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/3 "2018-05-21T17:39:47Z")

</div>

Thanks Yisreal! I actually found where the text string was missing in the code on Wix’s support page ([https://support.wix.com/en/article/creating-an-expandable-text-box-with-a-show-more-link-using-wix-code](https://support.wix.com/en/article/creating-an-expandable-text-box-with-a-show-more-link-using-wix-code)) and added it. This is the code Wix tells people to add:

1. **// how many characters to include in the shortened version**  
**2. const shortTextLength = 40;**  
**3. // read the full text and store it in the fullText variable**  
**4. fullText = $w(“#myTextElement”).text;**  
**5. // // grab the number of characters defined in shortTextLength and store them in the shortText variable** 6. **shortText = fullText.substr(0, shortTextLength) + “…”;**  
**7. // set the contents of the text element to be the short text**  
**8. $w(“#myTextElement”).text = shortText;**

As you can see on Line 8, it’s missing the string. It should be $w(“#myTextElement”).text === shortText;

The new problem, if anyone can help, is that - again per the instructions Wix has on the “Creating An Expandable Text Box…” - I have set the button to toggle (Show More, Show Less). The problem is that when the page opens, the Text Box is expanded when (according to the support page) it should be collapsed, with the toggled button to show the full text (Show More).

I can’t seem to make the fullText hide when the page first opens and gives the viewer the option to Show More.

This is the exact code Wix directs you to put in (for everything including the Text box, save for the correction I made above)

let fullText; // variable to hold the full text  
let shortText; // variable to hold the short version of the text

$w.onReady(function () {  
// how many characters to include in the shortened version  
const shortTextLength = 60;  
// read the full text and store it in the fullText variable  
fullText = $w(“#text46”).text;  
// // grab the number of characters defined in shortTextLength and store them in the shortText variable  
shortText = fullText.substr(0, shortTextLength) + “…”;  
// set the contents of #text46 to be the short text  
$w(“#text46”).text === shortTextLength;  
});

export function button8\_click(event, $w) {  
// if currently displaying short text, display the full text  
if ($w(“#text46”).text === shortText) {  
$w(“#text46”).text = fullText;  
$w(“#button8”).label = “Show less”;  
} else {  
// if currently displaying full text, display the short text  
$w(“#text46”).text = shortText;  
$w(“#button8”).label = “Show more”;  
}

}

---

<div class="post-metadata">

**Author:** ![info19569](https://avatars.discourse-cdn.com/v4/letter/i/6f9a4e/32.png) [@info19569](https://forum.wixstudio.com/u/info19569)\
**Post date:** [September 18, 2018, 2:02pm UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/4 "2018-09-18T14:02:30Z")

</div>

HELLO i have 10 working expandable texts on my website using these codes:

let fullText10; // variable to hold the full text  
let shortText10; // variable to hold the short version of the text

// For full API documentation, including code examples, visit [Velo API Reference - Wix.com](http://wix.to/94BuAAs)

$w.onReady( function () {  
// how many characters to include in the shortened version  
const shortText10Length = 0;  
// read the full text and store it in the fullText variable  
fullText10 = $w(“#text122”).html;  
// grab the number of characters defined in shortTextLength and store them in the shortText variable  
shortText10 = fullText10.substr(0, shortText10Length) + “”;  
// set the contents of the text element to be the short text  
$w(“#text122”).html = shortText10;  
});  
export function button14\_click() {  
// check the contents of the text element  
if ($w(“#text122”).html.length \< fullText10.length) {  
// if currently displaying short text, display the full text  
$w(“#text122”).html = fullText10;  
$w(“#button14”).label = “Show less”;  
} **else** {  
// if currently displaying full text, display the short text  
$w(“#text122”).html = shortText10;  
$w(“#button14”).label = “Show more”;  
}  
}

FOR YOUR REFERENCE THIS IS MY WEBSITE WITH EXPANDABLE TEXTS: [https://www.fridmanproperties.com/airbnb-vs-long-term-rentals](https://www.fridmanproperties.com/airbnb-vs-long-term-rentals)

---

<div class="post-metadata">

**Author:** ![johnnylou92](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/johnnylou92/32/10459_2.png) [@johnnylou92](https://forum.wixstudio.com/u/johnnylou92)\
**Post date:** [April 30, 2019, 4:39am UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/5 "2019-04-30T04:39:39Z")

</div>

Same issue and mind blown that no Wix or corvid Admin have commented back on this thread…

---

<div class="post-metadata">

**Author:** ![cgranvelle](https://avatars.discourse-cdn.com/v4/letter/c/d26b3c/32.png) [@cgranvelle](https://forum.wixstudio.com/u/cgranvelle)\
**Post date:** [August 20, 2019, 10:12pm UTC](https://forum.wixstudio.com/t/code-error-message-when-creating-an-expandable-text-box/42374/6 "2019-08-20T22:12:37Z")

</div>

Thank you Fridman, but in order to make it work, I had to use the procedure from Wix help to add an onClick Event Handler.  
See below:

**let** fullText150; // variable to hold the full text  
**let** shortText150; // variable to hold the short version of the text  
// For full API documentation, including code examples, visit [Velo API Reference - Wix.com](http://wix.to/94BuAAs)  
$w.onReady( **function** () {  
// how many characters to include in the shortened version  
**const** shortText150Length = 150;  
// read the full text and store it in the fullText variable  
fullText150 = $w(“#text74”).html;  
// grab the number of characters defined in shortTextLength and store them in the shortText variable  
shortText150 = fullText150.substr(0, shortText150Length) + “”;  
// set the contents of the text element to be the short text  
$w(“#text74”).html = shortText150;  
});  
export function button31\_click\_1(event) {  
// check the contents of the text element  
**if** ($w(“#text74”).html.length \< fullText150.length) {  
// if currently displaying short text, display the full text  
$w(“#text74”).html = fullText150;  
$w(“#button31”).label = “Show less”;  
} **else** {  
// if currently displaying full text, display the short text  
$w(“#text74”).html = shortText150;  
$w(“#button31”).label = “Show more”;
