onClick the same text for different buttons

Good day!
I need urgent help.
I don’t know why but even though I wrote different code for different buttons it opens the same text in full version.

Could you please to give me a piece of advice or point out my mistakes in my code.

let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
// За полной документацией по API, включая примеры кода, зайдите на Velo API Reference - Wix.com
$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// read the full text and store it in the fullText variable
fullText = $w(“#text19”).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 the text element to be the short text
$w(“#text19”).text = shortText;
});

$w.onReady( function () {
// how many characters to include in the shortened version
const shortTextLength = 40;
// read the full text and store it in the fullText variable
fullText = $w(" #text21").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 the text element to be the short text
$w(“#text21”).text = shortText;
});

//Add your code for this event here:
export function button4_click(event) {
// display the full text
$w( “#text19”).text = fullText;
// collapse the button
$w(“#button4”).collapse();
//Add your code for this event here:
}
export function button5_click(event) {
// display the full text
$w( “#text21”).text = fullText;
// collapse the button
$w(“#button5”).collapse();
//Add your code for this event here:
}

because you’re assigning the variable “fullText” to both of them. If you have 2 different texts, you need 2 different variables.
In the beginning of the code, write:

 let fullText1, fullText2;
let shortText1, shortText2;

Then when you assign the full text use:

fullText1 = $w("#textbox1").text;
fullText2 = $w("#textbox2").text;
shortText1 = fullText1.substr(0, shortTextLength) + "...";
shortText2 = fullText2.substr(0, shortTextLength) + "..."; 
1 Like

Thanks a lot! I’ve managed to do it.
But now I have such problem as a big space when the text is in short form.
However the preview shows “ok”

this is a mobile version