correct way to test for NULL

I’m having some trouble with an Ajax on change action. I’m have 4 varchar fields on my form, field1, field2, field3, and field4.
If a change is made to anotherfield1, either field1, field2, field3 or field4 should be updated. Specifically, if field1 is blank, it should
be update. If field1 is NOT blank, field2 should be updated, etc.
I’ve tried :
if ({field1} == “null”) ;
if ({field1} = ’ ') ;
etc.
What is the generally accepted way to test for NULL or blank?
Thanks!

try using php function empty({field1})
if that doesn’t work, maybe try something like:
$foo = {field1};
if (empty($foo)) {echo ‘empty’;}

You have is_null(), but, read bwalujo post, and check this table:
http://php.net/manual/en/types.comparisons.php

if ({field1} == “null”) ; <-- you’re actually just testing if {field1} is equal to a string containing the word “null”
if ({field1} = ’ ') ; <-- you are setting {field1} to an empty string; for comparisons you have to use double equal signs ==, i.e. if ({field1} == ’ ')

Thanks all, regarding ==“null”, that is what I thought too, but a similar post on this forum, it worked for someone else.
http://www.scriptcase.net/forum/forum/developers/programming/3895-solved-i-want-to-know-if-a-date-field-is-null-or-empty
I will try some of the other suggestions.

As suggested by bwalujo empty() is a good solution as it will catch empty strings, false, null ,etc.

This is from the PHP online manual:

[SIZE=16px]The following things are considered to be empty:[/SIZE]

  • [I]""[/I] (an empty string)
  • [I]0[/I] (0 as an integer)
  • [I]0.0[/I] (0 as a float)
  • [I]"0"[/I] (0 as a string)
  • NULL
  • FALSE
  • [I]array()[/I] (an empty array)
  • [I]$var;[/I] (a variable declared, but without a value)