This topic is locked
[SOLVED]

 Display custom JS error to user

6/27/2019 9:39:04 AM
PHPRunner General questions
C
cms001 author

Hi,I have Javascript to test a value the user enter on a webpage from the Javascript Onload event.

If the value is incorrect, I want to display a message on the page - "Entry Invalid" or "Entry Valid"

I am not sure how to display the custom error.
Thanks

C
cms001 author 6/28/2019

Hi all,

The JS code verify a South African ID number - this is working 100%

If it was entered correctly, it will add the date of birth and the gender, derived from the id number - this works all good.If the number is correct, it will turn green or red if invalid.
I was able to add an JS line "Alert()" - but this is not nice, I just want to add a message at the bottom of the id number field, or just below the id number field, to say "Number Valid" or "Number Invalid" - I am sure this should be simple, but I have never done this before - so ... please assist with this one.
Kind RegardsWalter
Partial code when the number was validated:

if (correct) {
dateofbirth.setValue(dobdate);

genderValue.setValue(gender);

idnumber.addStyle('color: green');


}

// otherwise, show the error

else {



dateofbirth.setValue('');

genderValue.setValue('');

idnumber.addStyle('color: red');



alert("Invalid Number");
}


Admin 6/28/2019

Check this article for inspiration:

https://xlinesoft.com/blog/2017/07/25/using-field-events/
The idea is to create a place holder for your custom message first and then you can use Field Events or any Javascript code to display your message.

C
cms001 author 7/5/2019

Hi,

There is also another solution to this, which may be a bit easier.
This section explain to add custom JS validation, where you add a custom js file to the system and call it from the field properties of a field value to be tested.
https://xlinesoft.com/phprunner/docs/validation_types.htm

Hopefully this will help as well.