Check the tag of post #public or #backend
If it's public
Create a public .js file in your Wix account
Name it as a "template.js"
copy the main code
function fullName(firstName, lastName){
return firstName + ' ' + lastName
}
and past it on template.js
Final Public file
//in template.js
export function fullName(firstName, lastName){
return firstName + ' ' + lastName
}
Â
Now you can reuse this function in any page
Just by importing the module name
import { fullName } from 'public/template';
// general import syntax
import { moduleName } from 'public/filename.js';
Let say we have 2 input element with first name and last name
After a button click
We will show the full name in a text
Final Page code
//Importing module from template js file
import { fullName } from 'public/template'
$w.onReady(()=>{
$w('#btn').onClick(()=>{
let firstName = $w('#inFirstName').value;
let lastName = $w('#inLastName').value;
//Calling the module
$w('#textDisplayFullName').text = fullName(firstName, lastName);
})
});
- inFirstName - id of an input element
- inLastName - id of an input element
- textDisplayFullName - id of text element
- btn - id of a button element