0 Replies - 168 Views - Last Post: 31 October 2009 - 09:31 PM

#1 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

At least one text box must be fill

Posted 31 October 2009 - 09:31 PM

Description: sometime you have many textboxes and you want at least one textbox must not be empty other wise the form will not submit.
<script type="text/javascript">
function check_textboxes(frmName){
	var frm = document.getElementById(frmName).elements;
	var count = frm.length;
	var i;
	var empty = false;
			if(frm[i].value != ""){
				empty = true;
		alert("Please fill at least one text box");
	return empty;	

<form name="form1" id="form1" method="post" action="" onsubmit="return check_textboxes(this.id)">
  <table width="400" border="0" cellspacing="1" cellpadding="2">
      <td width="122">Text Box1</td>
      <td width="278"><label>
        <input type="text" name="txt1" id="txt1">
      <td>Text Box2</td>
      <td><input type="text" name="txt2" id="txt2"></td>
      <td>Text Box3</td>
      <td><input type="text" name="txt3" id="txt3"></td>
      <td>Text Box4</td>
      <td><input type="text" name="txt4" id="txt4"></td>
      <td>Text Box5</td>
      <td><input type="text" name="txt5" id="txt6"></td>
      <td>Text Box6</td>
      <td><input type="text" name="txt6" id="txt5"></td>
      <td> </td>
        <input type="submit" name="button" id="button" value="Submit">

Is This A Good Question/Topic? 0
  • +

Page 1 of 1