Wix Tutorial - Create a word counter, using Wix Code

Add a word counter to your text box.

Elements:

User Input:

  • box: #colorBox

Wix Code:

export function textBox1_keyPress(event) {

    setTimeout(() => {

        let val = event.target.value;

        if(val.length === 0)

            return;

        let count = WordCount(val);

        $w("#count").text = "" + count;

    }, 10);

}

 

function WordCount(str) { 

    return str.split(" ").length;

}

Demo:

Number of words in text:

Count

Websites designed by WixCreate that use the above Wix Code:

None

Official Wix Expert & Wix Agency Partner

© 2020 by WIXCreate.com

I  All Rights Reserved  I  info@wixcreate.com  I  202-640-5440

facebook-2.gif