Trending December 2023 # Notion Buttons – Tutorial With 4 Practical Examples # Suggested January 2024 # Top 18 Popular

You are reading the article Notion Buttons – Tutorial With 4 Practical Examples updated in December 2023 on the website Cattuongwedding.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Notion Buttons – Tutorial With 4 Practical Examples

Notion is the best app for organizing your life. Personally, I use Notion for writing texts, planning my tasks and projects, as well as storing notes.

The unique selling point of Notion is its innovative combination of blocks and databases. However, one small hurdle so far has been the somewhat cumbersome process of making changes in the databases.

Fortunately, this problem has disappeared with one of the recent Notion updates – the introduction of Notion Buttons in March 2023.

In this post, I want to show you what this update means, how to create Notion Buttons and the use cases where you can employ these buttons.

As hinted earlier, with Notion Buttons, you can efficiently perform frequently used actions or insert content, and they can be inserted on any Notion page.

They can be used to:

Insert blocks on a page.

Add pages to a database.

Edit pages in a database.

Open specific pages in your Notion workspace.

Type “/” and search for “Button”.

Now you can label the button and even add an emoji.

Here, you can add the following steps:

Insert Blocks: Insert a Notion block above or below the button. In theory, you can insert any possible Notion block, even another Notion button.

Add Pages to: This will add a page to a database. Simply select the appropriate database and choose the properties that should be filled.

Edit Pages in: Edit pages in a database, so that you can change the date or status, for example. You can also use filters to specify that only pages with specific properties should be modified.

Show Confirmation: This option is useful when you want the user to confirm an action. It can be used, for example, when redirecting them to an external page in the next step.

Open Page: This opens an external page.

Now that you know how to create a Notion button, let’s explore what you can actually do with it. Below, I provide you with 4 specific application examples from my Notion templates:

AI Summarization of Notes in a Zettelkasten

I find this function very important for my Notion Zettelkasten, as it allows me to quickly create readable text from a series of unformatted notes.

Show or Hide All Answers in a Spaced Repetition Template

The Spaced Repetition method is one of the best techniques for reliably memorizing a large amount of information. My Spaced Repetition template now brings this method closer to the Notion community.

To achieve this, I selected the step “Edit Pages” and linked it to the Spaced Repetition database. To hide the answers, I chose the “Reveal Answers” property and instructed the checkbox to remain unchecked everywhere. To show the answers, I created another button where the checkbox is marked as active.

Start or End a Pomodoro Interval

The Pomodoro method is a time management technique developed by Francesco Cirillo in the late 1980s. It divides work into intervals, typically 25 minutes long, to ensure regular breaks for regeneration.

Francesco Cirillo used to measure time with his Pomodoro kitchen timer, hence the name Pomodoro.

My Notion template allows you to implement the Pomodoro technique directly in Notion and connect your work tasks with your Notion task manager.

The only drawback: The template does not include a Pomodoro kitchen timer :(.

With the help of a Notion button, you can start a new Pomodoro interval or end an ongoing interval. The database will track the duration of the interval, allowing you to monitor your work time.

To start a new Pomodoro interval, the Notion button adds a new page to the Pomodoro database. The start time is set to “Now,” and the status is set to “Active.”

The button to end the Pomodoro interval updates the database and all active pages. The end time is set to “Now,” and the status is changed to “Done.”

Adding New Habits and Marking them as Completed

In my Habit Compass template, I use Notion buttons to add new habits for the day and check them off.

Users of the template are invited to customize the button. For example, they can change the habit’s name and indicate which vision from the vision board it should be associated with.

“Check Habit” modifies database entries and marks the respective habit as completed.

In my tutorial, I showed you how I use Notion buttons in my workspace. However, I’m also curious about your experiences. How do you use Notion buttons in your work routine? Do you have any useful tips or tricks you’d like to share?

I look forward to hearing from you!

Yours, Philipp

You're reading Notion Buttons – Tutorial With 4 Practical Examples

Mariadb Tutorial: Learn Syntax, Commands With Examples

What is MariaDB?

MariaDB is a fork of the MySQL database management system. It is created by its original developers. This DBMS tool offers data processing capabilities for both small and enterprise tasks.

MariaDB is an improved version of MySQL. It comes with numerous inbuilt powerful features and many usabilities, security and performance improvements that you cannot find in MySQL.

Here are the features of MariaDB:

It operates under GPL, BSD or LGPL licenses.

MariaDB supports a popular and standard querying language.

It comes with many storage engines, including the high-performance ones that can be integrated with other relational database management systems.

It provides the Galera cluster technology.

MariaDB supports PHP, a popular language for web development.

MariaDB can run on different operating systems, and it supports numerous programming languages.

MariaDB comes with additional commands that are not available in MySQL. MySQL has features which have a negative impact on the performance of the DBMS. Such features have been replaced in MariaDB.

In this MariaDB tutorial, you will learn:

MariaDB vs. MySQL

Below are some key differences between MariaDB vs MySQL

Parameter MariaDB MySQL

More Options for Storage Engines MariaDB has 12 new storage engines that you won’t find in MySQL. It has fewer options for storage compared to MariaDB.

Speed Improvements MariaDB shows an improved speed when compared to MySQL. It comes with numerous features for optimizing speed. Such features include derived views/tables, subquery, execution control, disk access, and optimizer control. MySQL exhibits a slower speed when compared to MariaDB. It relies on only a few features for speed optimization, for example, hash indexes.

Faster cache/indexes With the Memory storage engine of MariaDB, an INSERT statement can be completed 24% than in the standard MySQL. The memory storage engine of MySQL is slower compared to that MariaDB.

Larger and Faster Connection Pool The thread pool provided by MySQL cannot support up to 200,000 connections per time.

Improved Replication In MariaDB, replication can be done safer and faster. Updates can also be done 2x faster compared to the traditional MySQL.

New Features/Extensions MariaDB comes with new features and extensions including the JSON, WITH and KILL statements. The new MariaDB features are not provided in MySQL.

Missing Features MariaDB lacks some of the features provided by the MySQL enterprise edition. To address this, it offers alternative open-source plugins. Hence, MariaDB users are able to enjoy the same functionalities as MySQL Enterprise Edition users. The Enterprise Edition of MySQL uses a proprietary code. Only users of MySQL Enterprise Edition have access to this.

How to install MariaDB Install as a Standalone Application

In order to use MariaDB, you have to install it on your computer.

The installation can be done by following the steps given below:

Once the download is complete, Open File

In the next window, you will be required to change the password for the root user.

Enter the password and confirm it by retyping the same password. If you want to permit access from remote machines, activate the necessary checkbox.

A progress bar showing the progress of the installation will be shown:

You now have MariaDB installed on your computer.

Working with Command Prompt

Now that you have MariaDB installed on your computer, it is time for you to launch it and begin to use it. This can be done via the MariaDB command prompt.

Follow the steps given below:

Step 2) Choose a MariaDB Command Prompt.

Step 3) The MariaDB command prompt will be started. It is now time to login. You should login as the root user and the password that you set during the installation of MariaDB. Type the following command on the command prompt:

MySQL -u root -p

Step 4) Enter the password and hit the return key. You should be logged in, as shown below:

You are now logged into MariaDB.

Data Types

MariaDB supports the following data types:

String data types

Numeric data types

Date/time data types

Large object data types

String Data Types

These include the following:

String Data Type Description

char(size) The size denotes the number of characters to be stored. It stores a maximum of 255 characters. Fixed-length strings.

varchar(size) The size denotes the number of characters to be stored. It stores a maximum of 255 characters. Variable-length strings.

text(size) The size denotes the number of characters to be stored. It stores a maximum of 255 characters. Fixed-length strings.

binary(size) The size denotes the number of characters to be stored. It stores a maximum of 255 characters. Fixed-size strings.

Numeric Data Types

They include the following:

Numeric Data Types Description

bit A very small integer value equivalent to tinyint(1). Signed values range between -128 and 127. Unsigned values range between 0 and 255.

int(m) A standard integer value. Signed values range between -2147483648 and 2147483647. Unsigned values range between 0 and 4294967295.

float(m, d) A floating point number with single precision.

double(m,d) A floating point number with double precision.

float(p) A floating point number.

Date/Time Data Types

These include the following:

Date/Time Data Type Description

Date Displayed in the form ‘yyyy-mm-dd.’ Values range between ‘1000-01-01’ and ‘9999-12-31’.

Datetime Displayed in the form ‘yyyy-mm-dd hh:mm:ss’. Values range between ‘1000-01-01 00:00:00’ and ‘9999-12-31 23:59:59’.

timestamp(m) Displayed in the form ‘yyyy-mm-dd hh:mm:ss’. Values range between ‘1970-01-01 00:00:01’ utc and ‘2038-01-19 03:14:07’ utc.

Time Displayed in the form ‘hh:mm:ss’. Values range between ‘-838:59:59’ and ‘838:59:59’.

Large Object Datatypes (LOB)

They include the following:

Large object Datatype Description

tinyblob Its maximum size is 255 bytes.

blob(size) Takes 65,535 bytes as the maximum size.

mediumblob Its maximum size is 16,777,215 bytes.

longtext It takes 4GB as the maximum size.

Create a Database and Tables

To create a new database in MariaDB, you should have special privileges which are only granted to the root user and admins.

To create a new database, you should use the CREATE DATABASE command which takes the following syntax:

CREATE DATABASE DatabaseName;

In this case, you need to create a database and give it the name Demo.

Start the MariaDB command prompt and login as the root user by typing the following command:

mysql -u root -p

Type the root password and hit the return key. You will be logged in.

Now, run the following command:

CREATE DATABASE Demo;

You have then created a database named Demo. It will be good for you to confirm whether the database was created successfully or not. You only have to show the list of the available databases by running the following command:

SHOW DATABASES;

The above output shows that the Demo database is part of the list, hence the database was created successfully.

MariaDB Select Database

For you to be able to use or work on a particular database, you have to select it from the list of the available databases. After selecting a database, you can perform tasks such as creating tables within the database.

To select a database, you should use the USE command. It takes the syntax given below:

USE database_name;

You need to use the Demo database. You can select it by running the following command:

USE Demo;

The above image shows that the MariaDB command prompt has changed from none to the name of the database that has been selected.

You can now go ahead and create tables within the Demo database.

MariaDB – Create Table

For you to be able to create a table, you must have selected a database. The table can be created using the CREATE TABLE statement. Here is the syntax for the command:

CREATE TABLE tableName (columnName columnType);

You can set one of the columns to be the primary key. This column should not allow null values.

We will create two tables within the Demo database, Book, and Price tables. Each table will have two columns.

Let’s begin by creating the Book table with two columns, id and name. Run the following command:

CREATE TABLE Book( id INT NOT NULL AUTO_INCREMENT, name VARCHAR(100) NOT NULL, PRIMARY KEY (id));

The PRIMARY KEY constraint has been used to set the id column as the primary key for the table. The AUTO_INCREMENT property will increment the values of the id column by 1 automatically for each new record inserted into the table. All the columns will not allow null values.

Now, create the second table, the Price table:

CREATE TABLE Price( id INT NOT NULL AUTO_INCREMENT, price float NOT NULL, PRIMARY KEY (id));

The id column has been set as the primary key for the table.

Showing Tables

Now that you have created the two tables, it will be good for you to conform whether the tables were created successfully or not. You can show the list of tables contained in a database by running the following command:

SHOW TABLES;

The above screenshot shows that the two tables were created successfully within the Demo database.

Showing Table Structure

To see the structure of any particular table, you can use the DESCRIBE command, commonly abbreviated as DESC. It takes the following syntax:

DESC TableName;

For example, to see the structure of the table named Book, you can run the following command;

DESC Book;

The table has two columns. To see the structure of the Price table, you can run the following command:

DESC Price;

CRUD and Clauses INSERT

To insert data into a MariaDB table, you should use the INSERT INTO statement. This command takes the syntax given below:

INSERT INTO tableName (column_1, column_2, ... ) VALUES (value1, value2, ... ), (value1, value2, ... ), ...;

The above syntax shows that you have to specify the table columns into which you want to insert data as well as the data that you need to insert.

Let us insert a record into the Book table:

INSERT INTO book (id, name) VALUES(1, 'MariaDB Book');

You have inserted a single record into the table. Insert a record into the Price table:

INSERT INTO price (id, price) VALUES(1, 200);

The record has been created.

SELECT

The SELECT statement helps us to view or see the contents of a database table. To see the contents of the Book table, for example, you need to run the following command:

SELECT * from book;

Now, view the contents of the Price table:

SELECT * from price;

Inserting Multiple Records

It is possible for us to insert multiple records into a MariaDB table at a go. To demonstrate this, run the following example:

INSERT INTO book (id, name) VALUES (2,'MariaDB Book2'), (3,'MariaDB Book3'), (4,'MariaDB Book4'), (5,'MariaDB Book5');

You can query the table to check whether the records were inserted successfully:

SELECT * FROM book;

The records were inserted successfully. Insert multiple records into the Price table by running this example:

INSERT INTO price (id, price) VALUES (2, 250), (3, 220), (4, 190), (5, 300);

Let’s confirm whether the records were created successfully:

SELECT * FROM price;

UPDATE

The UPDATE command helps us to change or modify the records that have already been inserted into a table. You can combine it with the WHERE clause to specify the record that is to be updated. Here is the syntax:

UPDATE tableName SET field=newValue, field2=newValue2,... [WHERE ...]

The UPDATE command can also be combined with clauses such as SET, WHERE, LIMIT, and ORDER BY. You will see this shortly:

Consider the table named Price with the following records:

Let’s change the price of the book with an id of 1 from 200 to 250:

UPDATE price SET price = 250 WHERE id = 1;

The command ran successfully. You can now query the table to see whether the change took place:

The above screenshot shows that the change has been implemented. Consider the table Book with the following records:

Let us change the name of the book named Book to MariaDB Book1. Notice that the book has an id of 1. Here is the command for this:

UPDATE book SET name = “MariaDB Book1” WHERE id = 1;

Check whether the change has been implemented:

The above screenshot shows that the change has been implemented successfully.

In the above examples, we have only changed one column at a time. However, it is possible for us to change multiple columns at a go. Let us demonstrate this using an example.

Let us use the Price table with the following data:

Let us change both the id and the price of the book with an id of 5. We will change its id to 6 and price to 6. Run the following command:

UPDATE price SET id = 6, price = 280 WHERE id = 5;

Now, query the table to check whether the change was made successfully:

The change was made successfully.

Delete

We use the DELETE command when we need to delete either one or many records from a table. Here is the syntax for the command:

DELETE FROM tableName [WHERE condition(s)] [LIMIT numberRows];

Consider the Price table with the following records:

We need to delete the last record from the table. It has an id of 6 and a price of 280. Let us delete the record:

DELETE FROM price WHERE id = 6;

The command ran successfully. Let us query the table to confirm whether the deletion was successful:

The output shows that the record was deleted successfully.

Where

The WHERE clause helps us to specify the exact location where we need to make a change. It is used together with statements such as INSERT, SELECT, UPDATE, and DELETE. Consider the Price table with the following data:

Suppose we need to see the records in which the price is less than 250. We can run the following command:

SELECT * FROM price WHERE price < 250;

All the records in which the price is below 250 have been returned.

The WHERE clause can be combined with the AND statement. Suppose we need to see all records in the Price table where the price is below 250 and id is above 3. We can run the following command:

SELECT * FROM price AND price < 250;

Only one record has been returned. The reason is that it has to meet all the conditions that have been specified, that is, id above 3 and price below 250. If any of these conditions is violated, then the record will not be returned.

The clause can also be combined with the OR command. Let us replace the AND in our previous command with OR and see the kind of output that we receive:

SELECT * FROM price OR price < 250;

We now get 2 records rather than 1. This is because, for a record of qualifying, it only has to meet one of the specified conditions.

Like

This clause is used to specify the data pattern when accessing table data in which an exact match is necessary. It can be combined with the INSERT, UPDATE, SELECT and DELETE statements.

You should pass the pattern of data you are looking for to the clause, and it will return either true or false. Here are the wildcard characters that can be used together with the clause:

%: for matching either 0 or more characters.

_: for matching a single character.

Here is the syntax for the LIKE clause:

SELECT field_1, field_2,... FROM tableName1, tableName2,... WHERE fieldName LIKE condition;

Let us demonstrate how to use the clause with the % wildcard character. Let us use the Book table with the following records:

We need to see all records in which the name begins with M. We can run the following command:

SELECT name FROM book WHERE name LIKE 'M%';

All records have been returned because their names begin with the letter M. To see all names that end with 4, you can run the following command:

SELECT name FROM book WHERE name LIKE '%4';

Only one name has been returned because it’s the only one meeting the condition.

We can also surround the search pattern by the wildcard:

SELECT name FROM book WHERE name LIKE '%DB%';

Other than the % wildcard, the LIKE clause can be used together with the _ wildcard. This is the underscore wildcard, and it will only look for a single character.

Let’s work with the Price table with the following records:

Let us check for the record in which the price is like 1_0. We run the following command:

SELECT * FROM price WHERE price LIKE '1_0';

It has returned the record in which the price is 190. We can also try another pattern:

SELECT * FROM price WHERE price LIKE '_2_';

It is possible for us to use the LIKE clause together with the NOT operator. This will return all the records that don’t meet the specified pattern. For example:

Let us use the Price table with the following records:

Let us find all the records where the price does not start with 2:

SELECT * FROM price WHERE price NOT LIKE '2%';

Only one record does not meet the specified pattern.

Order By

This clause helps us to sort out our records in either ascending or descending order. We use it with the SELECT statement, as shown below:

SELECT expression(s) FROM tables [WHERE condition(s)]

It is possible for us to use this clause without adding either the ASC or DESC part. For example:

We will use the Price table with the following records:

Run the following command against the table:

SELECT * FROM price WHERE price LIKE '2%.' ORDER BY price;

In the above command, we have ordered by the price. The records have been ordered with the prices in ascending order. That means that when we don’t specify the order, the sorting is done in ascending order by default.

Let us run the clause with the DESC option:

SELECT * FROM price WHERE price LIKE '2%' ORDER BY price DESC;

The records have been sorted with the price in descending order as we have specified.

Let us use the ORDER BY clause together with the ASC attribute:

SELECT * FROM price WHERE price LIKE '2%.' ORDER BY price ASC;

The records have been ordered but with the prices in ascending order. This is similar to when we use the ORDER BY clause without either ASC or DESC attributes.

DISTINCT

This clause helps us to do away with duplicates when selecting records from a table. This means that it helps us get unique records. Its syntax is given below:

SELECT DISTINCT expression(s) FROM tableName [WHERE condition(s)];

To demonstrate this, we will use the Price table with the following data:

When we select the price column from the table, we get the following result:

SELECT price FROM Price;

We have two records with a price of 250, creating a duplicate. We need to have only unique records. We can filter these by use of the DISTINCT clause as shown below:

SELECT DISTINCT price FROM Price;

We now don’t have any duplicates in the above output.

From

The FROM clause used for fetching data from a database table. It can also help when joining tables. Here is the syntax for the command:

SELECT columnNames FROM tableName;

To see the contents of the book table, run the following command:

SELECT * FROM price;

The clause can help you to fetch only a single column from a database table. For example:

SELECT price FROM Price;

Advanced Tasks Stored Procedure

A procedure is a MariaDB program that you can pass parameters to. A procedure doesn’t return values. To create a procedure, we use the CREATE PROCEDURE command.

To demonstrate how to create and call a procedure, we will create a procedure named myProcedure() that helps us select the name column from the book table. Here is the procedure:

DELIMITER $ CREATE PROCEDURE myProcedure() BEGIN SELECT name FROM book; END; ;

The procedure has been created. We have simply enclosed the SELECT statement within the BEGIN and END clauses of the procedure.

Now, we can call the procedure by its name as shown below:

CALL myProcedure();

The procedure returns the name column of the book table when called.

We can create a procedure that takes in a parameter. For example, we need to select the name of the book and filter using the book id. We can create the following procedure for this:

DELIMITER $ CREATE PROCEDURE myProcedure2(book_id int) BEGIN SELECT name FROM book WHERE id = book_id; END; ;

Above, we have created a procedure named myProcedure2(). This procedure takes one integer parameter named book_id which is the id of the book whose name we need to see. To see the name of the book with an id of 3, we can call the procedure as follows:

CALL myProcedure2(3);

Function

Unlike procedures, we must pass parameters to functions and a function must return a value. To create a function in MariaDB, we use the CREATE FUNCTION statement. The statement takes the following syntax:

CREATE FUNCTION function-name [(parameter datatype [, parameter datatype]) ] RETURNS datatype [LANGUAGE SQL BEGIN declaration-section executable-section END;

The above parameters are described below:

Parameter Description

DEFINER clause This parameter is optional. If you don’t specify it, the definer will become the user who created the function. If there is a need to specify a different definer, include the DEFINER clause in which the user_name will be the definer of the function.

function_name The name that is to be assigned to this function in the MariaDB.

parameter The parameter(s) passed to the function. During the creation of the function, all parameters are treated as IN parameters (rather than OUT/INOUT parameters).

return_datatype The data type of the return value of the function.

LANGUAGE SQL It affects the portability but not the function.

DETERMINISTIC The function will return one result only when given a number of parameters.

NOT DETERMINISTIC It is possible for the function to return a different result when given a number of parameters.

CONTAINS SQL Informs MariaDB that this function contains SQL. The database will not verify whether this is true.

NO SQL This clause is not used, and it has no impact on your function.

READS SQL DATA Tells MariaDB that this function will use SELECT statements to read data, but it won’t modify the data.

MODIFIES SQL DATA Tells MariaDB that this function will use INSERT, DELETE, UPDATE, and other DDL statements to modify SQL data.

declaration-section This is where local variables should be declared.

executable-section The function code should be added here.

Here is an example MariaDB function:

DELIMITER CREATE FUNCTION sumFunc (x INT ) RETURNS INT DETERMINISTIC BEGIN DECLARE sum INT; SET sum = 0; label1: WHILE sum <= 3000 DO SET sum = sum + x; END WHILE label1; RETURN sum; END; DELIMITER ;

We can then call the above function as follows:

select sumFunc(1000);

The command will return the following:

Once you are done with a function, it will be good for you to delete it. This is easy as you only have to call the DROP FUNCTION statement that takes the following syntax:

DROP FUNCTION function_name;

For example, to drop the function named myFunc, we can run the following command:

DROP FUNCTION myFunc; JOIN

When you need to retrieve data from more than one tables at a go, use MariaDB JOINS. This means that a JOIN works on two or more tables. The following three types of JOINS are supported in MariaDB:

INNER/SIMPLE JOIN

LEFT OUTER JOIN/LEFT JOIN

RIGHT OUTER JOIN/RIGHT JOIN

Let us discuss them one-by-one:

INNER JOIN

The inner join returns all rows from the tables in which the join condition is true. Its syntax is as follows:

SELECT columns FROM table-1 INNER JOIN table-2 ON table-1.column = table-2.column;

For example:

We will use our two tables, books, and book.

The book table has the following data:

The Price table has the following data:

The goal is to join the name column from the Book table and the price column from Price table into a single table. This is possible with an inner join, as demonstrated below:

SELECT book.name, price.price FROM book INNER JOIN price ON chúng tôi = chúng tôi

The command returns the following:

LEFT OUTER JOIN

This join returns all the rows from the left-hand table and only rows in which the join condition is true from the other table. Its syntax is as follows:

SELECT columns FROM table-1 LEFT [OUTER] JOIN table-2 ON table-1.column = table-2.column;

The OUTER keyword has been placed within square brackets because it is optional.

For example:

SELECT book.name, price.price FROM book LEFT JOIN price ON chúng tôi = chúng tôi

The command returns the following:

The last record in the above table has no matching value on the left. That is why it has been replaced with NULL.

RIGHT OUTER JOIN

This join returns all the rows from the right-hand table and only rows in which the join condition is true from the other table. Its syntax is as follows:

SELECT columns FROM table-1 RIGHT [OUTER] JOIN table-2 ON table-1.column = table-2.column;

The OUTER keyword has been placed within square brackets because it is optional.

For example:

SELECT book.name, price.price FROM book RIGHT JOIN price ON chúng tôi = chúng tôi

The command returns the following:

The reason is that all rows in the right-hand table were matched to those in the other table. If some of the rows did not match, we would have NULLs in the first column.

Practical Code Examples Using Javascript

Example#1: JavaScript Multiplication Table

Create a simple multiplication table asking the user the number of rows and columns he wants.

Solution:

var rows = prompt(“How many rows for your multiplication table?”); var cols = prompt(“How many columns for your multiplication table?”); rows = 10; cols = 10; createTable(rows, cols); function createTable(rows, cols) { var j=1; for(i=1;i<=rows;i++) { while(j<=cols) { j = j+1; } j = 1; } document.write(output); }

Example#2: JS Forms Example:

Create a sample form program that collects the first name, last name, email, user id, password and confirms password from the user. All the inputs are mandatory and email address entered should be in correct format. Also, the values entered in the password and confirm password textboxes should be the same. After validating using JavaScript, In output display proper error messages in red color just next to the textbox where there is an error.

Solution with Source Code:

var divs = new Array(); divs[0] = “errFirst”; divs[1] = “errLast”; divs[2] = “errEmail”; divs[3] = “errUid”; divs[4] = “errPassword”; divs[5] = “errConfirm”; function validate() { var inputs = new Array(); inputs[0] = document.getElementById(‘first’).value; inputs[1] = document.getElementById(‘last’).value; inputs[2] = document.getElementById(’email’).value; inputs[3] = document.getElementById(‘uid’).value; inputs[4] = document.getElementById(‘password’).value; inputs[5] = document.getElementById(‘confirm’).value; var errors = new Array(); for (i in inputs) { var errMessage = errors[i]; var div = divs[i]; if (inputs[i] == “”) document.getElementById(div).innerHTML = errMessage; else if (i==2) { var atpos=inputs[i].indexOf(“@”); var dotpos=inputs[i].lastIndexOf(“.”); else document.getElementById(div).innerHTML = “OK!”; } else if (i==5) { var first = document.getElementById(‘password’).value; var second = document.getElementById(‘confirm’).value; if (second != first) else document.getElementById(div).innerHTML = “OK!”; } else document.getElementById(div).innerHTML = “OK!”; } } function finalValidate() { var count = 0; for(i=0;i<6;i++) { var div = divs[i]; if(document.getElementById(div).innerHTML == “OK!”) count = count + 1; } if(count == 6) document.getElementById(“errFinal”).innerHTML = “All the data you entered is correct!!!”; } Example#3: POPUP Message using Event:

Display a simple message “Welcome!!!” on your demo webpage and when the user hovers over the message, a popup should be displayed with a message “Welcome to my WebPage!!!”.

Solution:

function trigger()

{

document.getElementById(“hover”).addEventListener(“mouseover”, popup);

function popup()

{

alert(“Welcome to my WebPage!!!”);

}

}

p

{

font-size:50px;

position: fixed;

left: 550px;

top: 300px;

}

7 Practical Steps For Engaging With Bloggers

Ideas for improving your blogger outreach

Word of mouth recommendations are nothing new, but with the evolution of social media, recommendations can now reach hundreds if not thousands or millions of people. Then of course, there’s the new breed of influencer – the blogger.

With established communities, bloggers command authority and trust from their readers having spent years honing their writing skill and content, studying their analytics and engaging with their readers. They know their audience better than anyone else and can talk about your brand in a way that they know their readers will relate to.

A positive opinion about a brand or product by a blogger can be transferred to their audience, resulting in referral traffic and sales.

So, we’ve established that there’s significant value in engaging bloggers, but how do you get bloggers to want to work with you and to talk about your brand?

Recommended Guide: Influencer Outreach Guide

Learn how to use free tools to find, monitor and interact with relevant influencers.

Download our Guide to Influencer Outreach.

Influence Bloggers to talk about your brand

1. Preparation

Before you start sourcing relevant bloggers to contact, spend some time working out what it is that you’re hoping to achieve, who your target audience is and what success looks like.

Most importantly, establish why a blogger would want to talk about your brand to their readers. Are you offering them products to review? Will your content drive traffic to their site? Are you giving them an experience of some kind such as an exclusive event? Asking this question will allow you to create a compelling offer for bloggers, making you more likely to succeed.

Define what it is that you want from the blogger and be upfront about it to them. Do you want them to tweet? Write a post? Write multiple posts? Share their content on your properties? The more information that you can provide upfront will allow them to set their expectations and then there won’t be any unpleasant surprises along the way.

2. Research

If you’re approaching a blogger because you have something that they’d want to share with their readers, make sure that you’ve spent time reading their site. This will tell you about their attitude towards brand collaborations and often they will clearly state whether or not they write reviews or are ‘PR friendly’.

This type of research will also give you good insight to whether yours is the type of brand that they’ve written about in the past and therefore likely to engage with you. Lastly, always check and respect their contact wishes, if they prefer to be contacted via their site, email, Twitter or phone, make sure that you contact them this way.

3. Build Rapport

Take some time to follow their social channels, this will give you an insight to their interests and personalities. It will also also give you an opportunity to start to engage with them so that they recognise your name and the things that you have in common. What’s more, if you can see on Twitter that they’re sick or on holiday, you’ll know to hold off of getting in touch with them. First impressions mean everything.

4. Flexibility

5. Customise

So many companies try to save time by sending a standard message cut and paste to every blogger. Bloggers get this type of contact all of the time and won’t be fooled. Spend the time to tailor your message, making it personal and where possible try and explain why you thought that your proposition might be relevant to their site. The investment in time will pay off.

6. Editorial Control

Recognise that you can’t control the content that the blogger writes in their post about you (unless you’re paying them and they’ve agreed to this). The blogger has complete editorial control and a recommendation or review will be much more authentic when written in their style, in keeping with their usual posts. Also, don’t expect to review a post before it goes live, it won’t happen.

7. Follow Up

Once you’ve contacted the blogger, give them some time to come back to you. Don’t be afraid to follow-up with them, sometimes your message ends up getting lost or they’ve received so many that they’ve forgotten to reply. It’s best to check. However, if they aren’t interested, handle the decline with dignity. It’s better to build long-term relationships than short-term gains.

Make sure that you follow-up on the promises that you have made to bloggers. If you have said that you’ll send assets over, make sure that you do it in a timely manner so that it’s still relevant. Where possible, if the blogger is kind enough to write about your brand, try and show their link some love using your social channels too. They’ll appreciate the recognition. Be sure to also email them to thank them.

The likelihood is that if you’ve done your job well, you’ll be able to work with them again in the future and will have a better understanding of them as a person and how they work.

Therefore it’s fundamental that you stay in touch after the campaign and don’t just ‘dump them’ because they’ve created the content that you were looking for. Be sure to check in with them, even if it’s replying to a tweet.

How To Switch Css Class Between Buttons Rendered With Map()?

When building web applications, developers often need to create buttons with dynamic styles. One of the most efficient ways to do this is by using the map() method in JavaScript. This method allows you to render multiple buttons with different styles based on their data. However, sometimes you might want to change the CSS class of a button dynamically based on user interaction or other events. In this article, we will discuss two different approaches to switch CSS class between buttons rendered with map() in JavaScript.

Algorithm

The algorithm to switch CSS class between buttons rendered with map() involves the following steps −

Create an array of objects with data for each button

Render the buttons using the map() method and assign a default CSS class

Add an event listener to each button to listen for user interaction

When a user interacts with a button, switch its CSS class to the desired one using the classList property

Approach 1: Using State and Ternary Operator

In this approach, we use the useState hook to create a state variable called “activeButton” that will store the ID of the button that is currently active. We then pass this state variable to the className attribute of the button as a ternary operator. If the button’s ID matches the activeButton state, we add the “active” CSS class, otherwise, we leave it blank.

import React, { useState } from "react"; const buttonsData = [ { id: 1, label: "Button 1" }, { id: 2, label: "Button 2" }, { id: 3, label: "Button 3" }, ]; const [activeButton, setActiveButton] = useState(null); setActiveButton(id); }; return ( { <button key={id} className={activeButton === id ? "active" : ""} {label} )) } ); }; export default App; Approach 2: Using Class-based Components and Conditional Rendering

In this approach, we use a class-based component instead of a functional component. We define the state and event handler in the class itself. The rest of the code is almost the same as the previous approach.

import React, { Component } from "react"; const buttonsData = [ { id: 1, label: "Button 1" }, { id: 2, label: "Button 2" }, { id: 3, label: "Button 3" }, ]; class App extends Component { state = { activeButton: null, }; this.setState({ activeButton: id }); }; render() { const { activeButton } = this.state; return ( { <button key={id} className={activeButton === id ? "active" : ""} {label} )) } ); } } export default App;

.default { background-color: gray; color: white; } .active { background-color: blue; color: white; } const buttonsData = [ { id: 1, label: “Button 1” }, { id: 2, label: “Button 2” }, { id: 3, label: “Button 3” }, ];

const buttonsContainer = document.getElementById(“buttons-container”);

const button = document.createElement(“button”); button.textContent = label; button.className = “default”; const activeButton = buttonsContainer.querySelector(“.active”); if (activeButton) { activeButton.classList.remove(“active”); } button.classList.add(“active”); }); buttonsContainer.appendChild(button); });

Example 2: Switching CSS Class With Keyboard Navigation

In this example, we will switch the CSS class of a button when the user navigates to it using the keyboard.

.default { background-color: gray; color: white; } .active { background-color: red; color: white; } const buttonsData = [ { id: 1, label: “Button 1” }, { id: 2, label: “Button 2” }, { id: 3, label: “Button 3” }, ];

const buttonsContainer = document.getElementById(“buttons-container”);

const button = document.createElement(“button”); button.textContent = label; button.className = “default”; const activeButton = buttonsContainer.querySelector(“.active”); if (activeButton) { activeButton.classList.remove(“active”); } button.classList.add(“active”); }); buttonsContainer.appendChild(button); });

When the focus event is triggered, we follow the same logic as in the previous example to switch the CSS class of the buttons.

Conclusion

In this article, we discussed two different approaches to switch CSS class between buttons rendered with map() in JavaScript. We first explained the algorithm to accomplish this task and then provided two different approaches with code and explanations. The first approach involves using the useState hook in React to create a state variable that stores the ID of the currently active button. We then use a ternary operator to switch the CSS class of the button based on the activeButton state. The second approach involves using a class-based component and conditional rendering to achieve the same result. We also provided two working examples to demonstrate how to switch the CSS class of buttons with user interaction and keyboard navigation. By following these approaches, you can create dynamic buttons with different styles and easily switch between them based on user interaction or other events.

How Xpath Attribute Works With Examples?

Definition of XPath attribute

For finding an XPath node in an XML document, use the XPath Attribute expression location path. We can use XPath to generate attribute expressions to locate nodes in an XML document. When there are certain uniquely recognized attribute values accessible in the container tag, we employ the XPath functions (contains or starts-with) with the attribute. The “@” symbol is used to access attributes.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Syntax:

Xpath Syntax is given as:

Within a single node

/path to/element[@attribute_name]

At any point in the document

//*[@attribute_name]

Within a node that has some value

/path to/element[@attribute_name='search value'] /path to/element[@attribute_name="search value"]

//*[@attribute_name='search string'] How XPath attribute works?

Attribute predicates are another approach to indicate the items we want to choose more accurately. They are divided into two types: [@attr=”value”] chooses only elements with the attr attribute set to a value, and [@attr] selects only elements with an attr attribute set to a value (set to any value).

For example, let’s see an XML code like:

/purchase/product[@id=”soap”]/name

The following examples, which deal with qualities, are a little more complicated.

1. Choose objects that begin with the word “imagebox”:

[starts-with(name(),’imagebox’)]

2.Only objects from the “gallery” set should be selected:

/*[@sets=',gallery,']

3.Select the following objects from the set “gallery” that begins with the name albums:

/*[starts-with(name(),'albums')] /*[@sets=',gallery,']

4.Choose between img_1 and img_ 2:

5.Select all objects in the “blue” or “flower” sets:

//*[@sets,',blue,') or contains(@sets,'flower')]

6.Select all objects in the “blue” set but not the “flower” set:

//*[contains(@sets,',blue,') and not(contains(@sets,'flower')]

7.Select all items in sets that start with the letter “pot”:

//*[starts-with(@sets,',pot')]

Following Observations could be taken to see how attribute works with Xpath functions:

– With absolute text or an attribute, we can also utilise the contains () and starts-with() methods.

Let’s take a real-time case:

When using the contains() and starts-with() methods, we need to be very careful about which attribute we utilize. We won’t be able to uniquely identify the element if the property value isn’t unique. The XPath won’t function if we use the “type” attribute to identify the “I’m Feeling Lucky” button.

The presence of two matching nodes indicates that the element has not been appropriately detected. The value of the type attribute is not unique in this case.

For instance

The attribute expression is

//chi/@name

The result would be

In the following section, we shall see how attribute works in java Programming to extract the specific element from the XML document rather than calling all the elements. Let’s get started:

Examples

Let us discuss examples of the XPath attribute.

Example #1: Using Simple Xpath Expression

chúng tôi

/stateinfo/client/@id

Output:

ii) Selecting all attribute value

This selects all attributes of the specified context node.

Output:

iii) Selecting discipline attribute

@discipline

Output:

Example #2

.xml

/Universe/*[@uname]

Explanation

With Xpath expression let’s see how to extract the value of an attribute.

Output:

/Universe/*[@uname='Star']

Output:

Find nodes by substring matching the value of an attribute.

Xpath Expression

/Universe/*[contains(@uname,'Ma')]

Output:

Find nodes using a substring that matches the beginning of an attribute’s value.

/Universe/*[starts-with(lower-case(@uname),'sta')]

Output:

Example #3: Using java

}

chúng tôi

Explanation

Output:

Conclusion

Therefore, this article offers a code example that shows how to implement this requirement by using the contains XML Path Language (XPath) Attribute function. In the following post, we’ll look at how to use XPath Functions to improve the position of elements on the available webpage.

Recommended Articles

This is a guide to XPath attribute. Here we discuss the definition, How XPath attribute works? And examples for better understanding. You may also have a look at the following articles to learn more –

Update the detailed information about Notion Buttons – Tutorial With 4 Practical Examples on the Cattuongwedding.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!