Hi
i have 10 texboxes,
to check the value of each textbox from database wheither it empty(null) or not empty and depending upon value, button is enabled/disabled, if one of them texbox have value (not null/not empty) then button will enable otherwise it disabled.

Are your 'textboxes' in different rows or columns?

Do you have 10 rows, each with a 'textbox' in?

Please provide information to how your databse is structured, as it is key to how we write the script to solve the problem

Matt

my sample code is below

<?php 
@require_once 'config/config.php';
@require_once 'config/session.php'; 
@require_once 'class/dbclass.php';
@require_once 'class/EmpRegister.php';

$emp = new EmpRegister();
$EmpID = $_REQUEST['EmpID'];
if($EmpID != NULL){
    $result = $emp->get($EmpID);
    if($result == NULL){
        $EmpID = '';
    }
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
 function chMd1()
 {
  // initialize form with empty field
  document.forms[0].Heamogram_1.disabled=false;
  document.forms[0].Heamogram_1.value="";
  document.forms[0].Heamogram_2.disabled=false;
  document.forms[0].Heamogram_2.value="";
  document.forms[0].Heamogram_3.disabled=false;
  document.forms[0].Heamogram_3.value="";
  document.forms[0].Heamogram_4.disabled=false;
  document.forms[0].Heamogram_4.value="";
  document.forms[0].Heamogram_5.disabled=false;
  document.forms[0].Heamogram_5.value="";
  document.forms[0].Heamogram_6.disabled=false;
  document.forms[0].Heamogram_6.value="";
  document.forms[0].Heamogram_7.disabled=false;
  document.forms[0].Heamogram_7.value="";
  document.forms[0].Heamogram_8.disabled=false;
  document.forms[0].Heamogram_8.value="";
  document.forms[0].Heamogram_9.disabled=false;
  document.forms[0].Heamogram_9.value="";
  document.forms[0].Heamogram_10.disabled=false;
  document.forms[0].Heamogram_10.value="";
  document.forms[0].Heamogram_11.disabled=false;
  document.forms[0].Heamogram_11.value="";
  document.forms[0].Heamogram_12.disabled=false;
  document.forms[0].Heamogram_12.value="";
  document.forms[0].Heamogram_13.disabled=false;
  document.forms[0].Heamogram_13.value="";
  document.forms[0].Heamogram_14.disabled=false;
  document.forms[0].Heamogram_14.value="";
  document.forms[0].Heamogram_15.disabled=false;
  document.forms[0].Heamogram_15.value="";
  document.forms[0].Heamogram_16.disabled=false;
  document.forms[0].Heamogram_16.value="";
  document.forms[0].Heamogram_17.disabled=false;
  document.forms[0].Heamogram_17.value="";
  document.forms[0].Heamogram_18.disabled=false;
  document.forms[0].Heamogram_18.value="";
  document.forms[0].Heamogram_19.disabled=false;
  document.forms[0].Heamogram_19.value="";
  document.forms[0].Heamogram_20.disabled=false;
  document.forms[0].Heamogram_20.value="";
  document.forms[0].Heamogram_21.disabled=false;
  document.forms[0].Heamogram_21.value="";
  document.forms[0].Heamogram_22.disabled=false;
  document.forms[0].Heamogram_22.value="";
  document.forms[0].Heamogram_23.disabled=false;
  document.forms[0].Heamogram_23.value="";
  document.forms[0].Heamogram_24.disabled=false;
  document.forms[0].Heamogram_24.value="";
  document.forms[0].Heamogram_25.disabled=false;
  document.forms[0].Heamogram_25.value="";
  document.forms[0].Heamogram_26.disabled=false;
  document.forms[0].Heamogram_26.value="";


//  document.forms[0].Sero_10.disabled=false;
 // document.forms[0].Sero_10.value="";

  //document.forms[0].goServer.disabled=false;

  for(var i=0;i<document.forms[0].elements.length;i++)
  {
    if(document.forms[0].elements[i].name=="Heamogram_test")
    {
     if(document.forms[0].elements[i].value=="0")
     {
       if(document.forms[0].elements[i].checked==true){

        document.forms[0].Heamogram_1.disabled=true;
        document.forms[0].Heamogram_2.disabled=true;
        document.forms[0].Heamogram_3.disabled=true;
        document.forms[0].Heamogram_4.disabled=true;
        document.forms[0].Heamogram_5.disabled=true;
        document.forms[0].Heamogram_6.disabled=true;
        document.forms[0].Heamogram_7.disabled=true;
        document.forms[0].Heamogram_8.disabled=true;
        document.forms[0].Heamogram_9.disabled=true;
        document.forms[0].Heamogram_10.disabled=true;
        document.forms[0].Heamogram_11.disabled=true;
        document.forms[0].Heamogram_12.disabled=true;
        document.forms[0].Heamogram_13.disabled=true;
        document.forms[0].Heamogram_14.disabled=true;
        document.forms[0].Heamogram_15.disabled=true;
        document.forms[0].Heamogram_16.disabled=true;
        document.forms[0].Heamogram_17.disabled=true;
        document.forms[0].Heamogram_18.disabled=true;
        document.forms[0].Heamogram_19.disabled=true;
        document.forms[0].Heamogram_20.disabled=true;
        document.forms[0].Heamogram_21.disabled=true;
        document.forms[0].Heamogram_22.disabled=true;
        document.forms[0].Heamogram_23.disabled=true;
        document.forms[0].Heamogram_24.disabled=true;
        document.forms[0].Heamogram_25.disabled=true;
        document.forms[0].Heamogram_26.disabled=true;

        //document.forms[0].Sero_10.disabled=true;

        //document.forms[0].goServer.disabled=true;
       }
     }

    }
  }
 }
</script>
</head>

<body>
<table  width="60%" height="654" border="0" align="left" cellpadding="0" cellspacing="0">
  <tr>
    <td >INVESTIGATION</div></td>
    <td ><div align="center" class="style4"><strong>OBSERVED IN PATIENT</div></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Heamogtam Report</td>
    <td ><strong>
      <input type="radio" name="Heamogram_test" value="1" <?php echo $result[0]['Heamogram_test'] == '0' ? 'selected' : ''; ?> onClick="chMd1()" />
      Yes
      <input type="radio" name="Heamogram_test" value="0" onClick="chMd1()" <?php echo $result[0]['Bio_chem_test'] == '0' ? 'selected' : ''; ?> checked="checked" />
      No </td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Haemoglobin</td>
    <td ><input type="text" name="Heamogram_1" id="Heamogram_1" disabled="disabled" value="<?php echo $result[0]['Heamogram_1'];?>" tabindex="11"/></td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
  </tr>
  <tr>
    <td >Total Leukocyte count</td>
    <td  ><input type="text" name="Heamogram_2" id="Heamogram_2" disabled="disabled" value="<?php echo $result[0]['Heamogram_2'];?>" tabindex="
                            12"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Neutrophilis</td>
    <td ><input type="text" name="Heamogram_3" id="Heamogram_3" disabled="disabled" value="<?php echo $result[0]['Heamogram_3'];?>" tabindex="13"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Lymphocytes</td>
    <td ><input type="text" name="Heamogram_4" id="Heamogram_4" disabled="disabled" value="<?php echo $result[0]['Heamogram_4'];?>" tabindex="14"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Eosinophils</td>
    <td ><input type="text" name="Heamogram_5" id="Heamogram_5" disabled="disabled" value="<?php echo $result[0]['Heamogram_5'];?>" tabindex="15"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Monocytes</td>
    <td ><input type="text" name="Heamogram_6" id="Heamogram_6" disabled="disabled" value="<?php echo $result[0]['Heamogram_6'];?>" tabindex="16"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >E.S.R. (Westergren)</td>
    <td ><input type="text" name="Heamogram_7" id="Heamogram_7" disabled="disabled" value="<?php echo $result[0]['Heamogram_7'];?>" tabindex="17"/></td>
    <td >&nbsp;</td>
    <td >&nbsp;</td>
  </tr>
  <tr>
    <td >Platelet Count</td>
    <td ><input type="text" name="Heamogram_8" id="Heamogram_8" disabled="disabled" value="<?php echo $result[0]['Heamogram_8'];?>" tabindex="18"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Blood Group</td>
    <td ><input type="text" name="Heamogram_9" id="Heamogram_9" disabled="disabled" value="<?php echo $result[0]['Heamogram_9'];?>" tabindex="19"/></td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td >Bleeding Time</td>
    <td ><input type="text" name="Heamogram_10" id="Heamogram_10" disabled="disabled" value="<?php echo $result[0]['Heamogram_10'];?>" tabindex="20"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td >Clotting Time</td>
    <td ><input type="text" name="Heamogram_11" id="Heamogram_11" disabled="disabled" value="<?php echo $result[0]['Heamogram_11'];?>" tabindex="21"/></td>
    <td colspan="2" >&nbsp;</td>
  </tr>
  <tr>
    <td height="24" >&nbsp;</td>
    <td ><div align="center" class="style55">URINE ANYLYSIS</div></td>
    <td colspan="2" ><span class="style4"></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Albumin</td>
    <td ><input type="text" name="Heamogram_12" id="Heamogram_12" disabled="disabled" value="<?php echo $result[0]['Heamogram_12'];?>" tabindex="22"/></td>
    <td width="24%" ><span class="style55 style7">Pus Cells</td>
    <td width="27%" ><input type="text" name="Heamogram_18" id="Heamogram_18" disabled="disabled" value="<?php echo $result[0]['Heamogram_18'];?>" tabindex="23"/></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Sugar</td>
    <td ><input type="text" name="Heamogram_13" id="Heamogram_13" disabled="disabled" value="<?php echo $result[0]['Heamogram_13'];?>" tabindex="24"/></td>
    <td >Epithelial Cells</td>
    <td ><input type="text" name="Heamogram_19" id="Heamogram_19" disabled="disabled" value="<?php echo $result[0]['Heamogram_19'];?>" tabindex="25"/></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Acetone</td>
    <td ><input type="text" name="Heamogram_14" id="Heamogram_14" disabled="disabled" value="<?php echo $result[0]['Heamogram_14'];?>" tabindex="26"/></td>
    <td >RBC</td>
    <td ><input type="text" name="Heamogram_20" id="Heamogram_20" disabled="disabled" value="<?php echo $result[0]['Heamogram_20'];?>" tabindex="27"/></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Bile Salt</td>
    <td ><input type="text" name="Heamogram_15" id="Heamogram_15" disabled="disabled" value="<?php echo $result[0]['Heamogram_15'];?>" tabindex="28"/></td>
    <td >Bacteria</td>
    <td ><input type="text" name="Heamogram_21" id="Heamogram_21" disabled="disabled" value="<?php echo $result[0]['Heamogram_21'];?>" tabindex="29"/></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Bilirubin</td>
    <td ><input type="text" name="Heamogram_16" id="Heamogram_16" disabled="disabled" value="<?php echo $result[0]['Heamogram_16'];?>" tabindex="30"/></td>
    <td >Crystals</td>
    <td ><input type="text" name="Heamogram_22" id="Heamogram_22" disabled="disabled" value="<?php echo $result[0]['Heamogram_22'];?>" tabindex="31"/></td>
  </tr>
  <tr>
    <td ><span class="style55 style7">Urobilinogen</td>
    <td ><input type="text" name="Heamogram_17" id="Heamogram_17" disabled="disabled" value="<?php echo $result[0]['Heamogram_17'];?>" tabindex="32"/></td>
    <td ><span class="style55 style7">Casts </td>
    <td ><input type="text" name="Heamogram_23" id="Heamogram_23" disabled="disabled" value="<?php echo $result[0]['Heamogram_23'];?>" tabindex="33"/></td>
  </tr>
  <tr>
    <td >Others</td>
    <td ><input type="text" name="Heamogram_24" id="Heamogram_24" disabled="disabled" value="<?php echo $result[0]['Heamogram_24'];?>" tabindex="34"/></td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td >&nbsp;</td>
    <td ><div align="center" class="style55">OTHER TEST</div></td>
    <td colspan="2" ><span class="style4"></td>
  </tr>
  <tr>
    <td >Urine Preg. Test</td>
    <td ><input type="text" name="Heamogram_25" id="Heamogram_25" disabled="disabled" value="<?php echo $result[0]['Heamogram_25'];?>" tabindex="35"/></td>
    <td colspan="2">&nbsp;</td>
  </tr>
  <tr>
    <td >Ps for M.P. / Opinion</td>
    <td ><input type="text" name="Heamogram_26" id="Heamogram_26" disabled="disabled" value="<?php echo $result[0]['Heamogram_26'];?>" tabindex="36"/></td>
    <td colspan="2">&nbsp;</td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>

<?php if(!not_null($result[0]['Heamogram_26'])){echo "disabled";}?>

Or this will do the same thing:

<?php if(!not_null($result[0]['Heamogram_26'])){echo "disabled='disabled'";}?>

Hi mattster,
Thanks for reply, i want actually if this Heamogram, out of 26 texboxes, one them has value (means not null) then button will enable and if all 26 texboxes are null then button will be disabled.

Hi,

You may loop for all such values and can set button property accordingly. with editing of mattsters's answer, script can be something like below:

$flag = true;
for ($i=1; $i<=26; $i++) {
    if(!not_null($result[0]['Heamogram_'.$i])) {
        $flag = false;
        break;
    }
}
if ($flag == false)
    $property = "disabled='disabled'";

and then you mmy echo $property wherever you want in your script/code

hi,
i am trying it but not works "Fatal error: Call to undefined function not_null() "

you're going to want to do this client side (js) so that you can detect when a user has input text into one of the boxes

//my sudo code (write your own code)
func boxchanged() {
    if has value set enabled
    else call checkboxes()
}

func checkboxes() {
    foreach box {
        if box has value {
            break
            set enabled
        }
    }
    set disabled
}
//add boxchanged() to the onchange for each box

hi jstfsklh211,
thanks for reply, but i want diff way plz read above post carefuly and suggest for the same

Something like this?

<?php 

if(!not_null($result[0]['Heamogram_26']) || !not_null($result[0]['Heamogram_25']) !not_null($result[0]['Heamogram_24']) || ...){
    echo "disabled='disabled'";
}

?>

Hi mattster,
i try this code but erron in that "undefined function not_null()"

Sorry my bad, meant is_null()

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.