Checking of Empty Textbox

Check Whether a TextBox is empty or not

You should use String.IsNullOrEmpty() to make sure it is neither empty nor null (somehow):

if (String.IsNullOrEmpty(textBox1.Text))
{
// Do something...
}

More examples here.

For practical purposes you might also consider using String.IsNullOrWhitespace() since a TextBox expecting whitespace as input probably negates any purpose, except in case of, say, letting the user pick a custom separator for stuff.

How to check for empty textbox

If you want to check empty for all text box control in your page .Try IsNullOrWhiteSpace

 foreach (Control child in this.Controls)
{
TextBox textBox = child as TextBox;
if (textBox != null)
{
if (!string.IsNullOrWhiteSpace(textBox.Text))
{
MessageBox.Show("Text box can't be empty");
}
}
}

Check if textbox is empty - is there a better way?

Not really - however, you could make a little extension if it would save you time:

public static class TextBoxExtensions
{
public static bool IsEmpty(this TextBox textBox)
{
return string.IsNullOrWhiteSpace(null == textBox ? null : textBox.Text);
}
}

usage:

if(TextBox1.IsEmpty())
{
....

Checking textbox if it's empty in Javascript

It should be this:

var chatinput = document.getElementById("chatinput").value;
if (chatinput == "" || chatinput.length == 0 || chatinput == null)
{
// Invalid... Box is empty
}

Or shorthanded:

if (!document.getElementById("chatinput").value)
{
// Invalid... Box is empty
}

The = assigns a value whereas == checks whether the values are equal.

Checking if text boxes are empty

You can try to loop at your container (ie form, panel, groupbox) for each textbox without content, then increment whenever there is a textbox that doesn't have content.

Example:

          Dim checkr as integer = 0
Dim this As Control
For Each this In that.Controls
If TypeOf this Is TextBox Then
If this.text = "" then
Checkr += 1
End if
End If
Next

If checkr > 0 then
msgbox("Cannot proceed because a textbox has no content")
Else
'......(what you were gonna do)
End If

checking to see if a text box is empty in php

<?php

include "connect.php";
if(isset($_POST["submit"]))
{
$ownerName = isset($_POST['OwnerName']) ? $_POST['OwnerName']: '';
$location = isset($_POST['Location']) ? $_POST['Location']: '';
$phoneNumber = isset($_POST['PhoneNumber']) ? $_POST['PhoneNumber']: '';

//preventing sql injection
/*
$ownerName = mysqli_real_escape_string($con, $ownerName);
$$location = mysqli_real_escape_string($con, $ownerName);
$$phoneNumber = mysqli_real_escape_string($con, $ownerName);
*/

if(empty($ownerName) || empty($location) || empty($phoneNumber)){
echo("Missing Information!");

/*if(is_numeric($phoneNumber) ){
settype($phoneNumber, "integer");
}*/


}else{
$query = "INSERT INTO OWNER VALUES ('$ownerName','$location', $phoneNumber)";




if (!mysqli_query($con,$query))
{
die('Error: ' . mysqli_error($con));
}
echo "<script type='text/javascript'>alert('1 record added')</script>";
}
mysqli_close($con);
?>

Also try using var_dump($_POST) to see what is sent.

EDIT:

I've updated if/else statement so now it should work. Also, make sure you have your error reporting enabled:

<?php
// Turn off error reporting
error_reporting(0);

// Report runtime errors
error_reporting(E_ERROR | E_WARNING | E_PARSE);

// Report all errors
error_reporting(E_ALL);

// Same as error_reporting(E_ALL);
ini_set("error_reporting", E_ALL);

// Report all errors except E_NOTICE
error_reporting(E_ALL & ~E_NOTICE);
?>

Checking if a textbox is empty in Javascript

onchange will work only if the value of the textbox changed compared to the value it had before, so for the first time it won't work because the state didn't change.

So it is better to use onblur event or on submitting the form.