how to show custom text (error message) if email is incorrect or not entered

I’m not a programmer so I’m looking for help here. I need a code to perform the following functions:

  1. if the email is not written and the user press the subscribe button - show() first text like this is an error message
  2. if the email is written incorrectly and the user press the subscribe button- show() second text also like this is an error message

I hope this is really easy task and someone help me very fast :slight_smile: thanks

Все начинается отсюда…

$w.onReady(()=>{
	
});

Добавляем новую кнопку…

$w.onReady(()=>{
	$w('#myButtonIDhere').onClick(()=>{
		console.log("Я не знаю, как я это сделaлa);
		
	});
});

Теперь добавим…

$w.onReady(()=>{
	$w('#myButtonIDhere').onClick(()=>{
		console.log("Я не знаю, как я это сделaлa);
		
		//SHOW....
		$w('#yourElementIdYouWantToShowOrHide').show();
		//...or HIDE...
		$w('#yourElementIdYouWantToShowOrHide').hide();
	});
});

Первая цель достигнута!

But this is still not complete right?
So what do you still need to complete your task?

You need an IF-ELSE-QUERY to check if your INPUT-FIELD has VALUE or not.

if(...) {...}
else {...}
if($w('#input1').value) {console.log("электронная почта правильная");}
else {console.log("электронная почта не правильная");}

Now try to put all together…

$w.onReady(()=>{
	$w('#myButtonIDhere').onClick(()=>{
		console.log("Я не знаю, как я это сделaлa);
		
		if($w('#input1').value) {
		    console.log("электронная почта правильная");
			$w('#yourElementIdYouWantToShowOrHide').show();
		}
		else {
		    console.log("электронная почта не правильная");
			$w('#yourElementIdYouWantToShowOrHide').hide();
		}
	});
});

обана! это уже похоже на что-то! :grin:

okay its working! so I do this

import wixData from “wix-data” ;

$w . onReady (()=>{
$w ( ‘#button1’ ). onClick (()=>{
console . log ( “message” );

    **if** ( $w ( '#input1' ). value ) { 
        console . log ( "first error" ); 
        $w ( '#text6' ). show (); 
        $w ( '#text5' ). hide (); 
    } 
    **else**  { 
        console . log ( "second error" ); 
        $w ( '#text6' ). hide (); 
        $w ( '#text5' ). show (); 
    } 
}); 

});

but now I have 2 problems:

  1. both texts are shown already on a page before user entered the email

  2. text didn’t hide when user enter a valid email and a success message appear

Make sure that your element-ID’S are all correct.

import wixData from "wix-data";

$w.onReady(()=>{
    $w('#text5').expand();
    $w('#text6').expand();
    $w('#text5').hide();
    $w('#text6').hide();

    $w('#button1').onClick(()=>{
        console.log("button clicked");
        if($w('#input1').value) {
            console.log("value ok");
            $w('#text6').show();
            $w('#text5').hide();
        }
        else {
            console.log("value not ok");
            $w('#text6').hide();
            $w('#text5').show();
        }
    });
});

thanks it’s working, at the beginning both text message are hidden. but when I enter a correct email and even have a successful message, error text message doesn’t disappear

You checked the → ID ← of the error-text-element?
Is it really - → “text5” ?

Another question - → your both textmessages are NOT connected with a DATASET ?

Maybe you want us to show the setup of your little example?

Also do not forget, this example is only checking for a value inside of the INPUT-ELEMENT. It is not checking if the entered e-mail was written right or wrong.

If you wanna check more then just the value, you will have to work with → VALIDATION-CHECK.

https://www.wix.com/velo/reference/$w/textinput/valid
https://www.wix.com/velo/reference/$w/textinput/oncustomvalidation