Check in JavaScript whether a location field is empty

49 views
Skip to first unread message

Michael Schädlich

unread,
Nov 27, 2025, 4:54:59 PM (12 days ago) Nov 27
to mementodatabase

Hello,

I have a location field in a table with two coordinate values (decimal numbers separated by commas). The address is in a separate field. The field with the coordinates is obviously not a normal text field, but a kind of object.

I also have a button with JavaScript that calculates the coordinates of the so-called Maidenhead locator and writes them to a text field. This works as long as the location field is filled in.

Although it is unlikely that this will happen, I would like to check in the JavaScript whether the location field is empty and, if so, write an error message in the field with the Maidenhead locator.

Unfortunately, I cannot find the correct syntax to check for an empty location field. Can anyone help me?

Thanks: Michael

Michael Schädlich

unread,
Nov 27, 2025, 5:17:49 PM (12 days ago) Nov 27
to mementodatabase
I found the solution myself, and it's simpler than I thought. "pos" is the variable that contains the content of the location field. And with
If (pos !== null) {
...
} else {
...
}
I can test whether the object is empty or not.

Mmm

unread,
Nov 28, 2025, 10:57:30 AM (11 days ago) Nov 28
to mementodatabase
Так тоже работает:
If ( pos ) {
    ...
} else {
    ...
}

>>> Any value that is not false, undefined, null, 0, -0, NaN, or the empty string (""), and any object, including a Boolean object whose value is false, is considered truthy when used as the condition. 

Поля–массивы можно проверять так:
If ( items.length > 0 ) {
    ...
} else {
    ...
}

Проверку поля–дата упоминал:

пятница, 28 ноября 2025 г. в 01:17:49 UTC+3, michael.s...@gmail.com:
Reply all
Reply to author
Forward
0 new messages