how to validate button for anyone textbox should be entered

Posted by Kranthi under JavaScript on 11/17/2010 | Points: 10 | Views : 2109 | Status : [Member] | Replies : 1
i have 3 textboxes and one searchbutton if user entered search buttton without entering input in anytextboxes means it should alert anyone textbox should be entered.
(that is textbox1 or textbox2 or textbosx3) anyone should be mendaory anyone reply me its urgent plz


Posted by: SheoNarayan on: 11/17/2010 [Administrator] HonoraryPlatinum | Points: 25

Hi Kranthi,

Below is the code, I have written especially for you.

    <asp:TextBox ID="TextBox1" runat="server" />

<asp:TextBox ID="TextBox2" runat="server" />
<asp:TextBox ID="TextBox3" runat="server" />
<asp:Button ID="btnSu" runat="server" OnClientClick="return Validate()" Text="Submit" />
<script language="javascript">
function Validate() {
if ($("#TextBox1").val().length == 0 && $("#TextBox2").val().length == 0 && $("#TextBox3").val().length == 0) {
alert("Sorry, please write at least in any one of the textbox");
return false;
else {
return true;

Above has three textboxes and one button. User has to enter in at least one textbox or he/she will get alert message.


Sheo Narayan

Kranthi, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response