*hi guys..i have a problem with my php code..i have use onchange event..but it's not working! i don't know why! :'(

*let me explain first..
- i want if i select a state then next the branch will appears auto if related..but only the related branch will appear..not all branch will appear..

my question is:
- why the state if selected doesn't changed the branch? ..still out all of the name of branch..

- how to make the onchange event is success after selected?

but every state and branch have their own code
for state:
eg: PENANG - 07

for branch:
eg: GEORGETOWN - 07041011

NEGERI = state
CAWANGAN = branch
*

here my code in detail.php :*

<?php 
 session_start();
 include('conn.php');

?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>FORM UTAMA</title>
<script language="javascript" src="calendar/calendar.js"></script>

<link href="calendar/calendar.css" rel="stylesheet" type="text/css">


<script language="javascript" src="cal2.js"></script>
<script language="javascript" src="cal_conf2.js"></script>
<link rel="stylesheet" href="calendar.css">

<script language="JavaScript">
if (document.form1.NEGERI.value==' ')
{
    alert("Sila Masukkan Negeri");
    return false;
}
else if (dokument.form1.CAWANGAN.value==' ')
{
    alert("Sila Masukkan Cawangan");
    return false;
}
else if (dokument.form1.TARIKH_PERMOHONAN.value==' ')
{
    alert("Sila Masukkan Tarikh Permohonan");
    return false;
}
else if (dokument.form1.TARIKH_SURATCAWANGAN.value==' ')
{
    alert("Sila Masukkan Tarikh Surat Cawangan");
    return false;
}
else if (dokument.form1.TARIKH_SURAT.value==' ')
{
    alert("Sila Masukkan Tarikh Surat");
    return false;
}
else if (dokument.form1.NAMA.value==' ')
{
    alert("Sila Masukkan Nama");
    return false;
}
else if (dokument.form1.NO_KPT.value==' ')
{   
    alert("Sila Masukkan no kpt");
    return false;
}
else if (dokument.form1.KETURUNAN.value==' ')
{
    alert("Sila Masukkan Keturunan");
    return false;
}
else if (dokument.form1.DOKUMEN.value==' ')
{
    alert("Sila Masukkan Dokumen");
    return false;
}
else if (dokument.form1.NO_DOKUMEN.value==' ')
{
    alert("Sila Masukkan No dokumen");
    return false;
}
else if (dokument.form1.TARIKH_PERMOHONAN.value==' ')
{
    alert("Sila Masukkan Tarikh permohonan");
    return false;
}
else if (dokument.form1.TARIKH_TERIMAFAIL.value==' ')
{
    alert("Sila Masukkan Tarikh terimafail");
    return false;
}
else if (dokument.form1.TARIKH_TEMUDUGA.value==' ')
{
    alert("Sila Masukkan Tarikh temuduga");
    return false;
}
else if (dokument.form1.STATUS_TEMUDUGA.value==' ')
{
    alert("Sila Masukkan Status temuduga");
    return false;
}

else if (dokument.form1.NO_RUJNEG.value==' ')
{
    alert("Sila Masukkan No rujneg");
    return false;
}
else if (dokument.form1.NO_RUJIP.value==' ')
{
    alert("Sila Masukkan No rujip");
    return false;
}
else if (dokument.form1.TAHAP_PERMOHONAN.value==' ')
{
    alert("Sila Masukkan Tahap permohonan");
    return false;
}
else if (dokument.form1.TARAF_KP.value==' ')
{
    alert("Sila Masukkan Taraf kp");
    return false;
}
else if (dokument.form1.NAMA_PEGAWAI.value==' ')
{
    alert("Sila Masukkan Nama pegawai");
    return false;
}
else if (dokument.form1.NO_KPT.value==' ')
{
    alert("Sila Masukkan No kpt");
    return false;
}
else if (dokument.form1.UNIT_PEGAWAI.value==' ')
{
    alert("Sila Masukkan Unit pegawai");
    return false;
}
else if (dokument.form1.JAWATAN_PEGAWAI.value=='')
{
    alert("Sila Masukkan Jawatan pegawai");
    return false;
}
else
{
    return true;
}

}

 </script>

<script type="text/javascript">


function getXMLHTTP() { //fuction to return the xml http object
        var xmlhttp=false;  
        try{
            xmlhttp=new XMLHttpRequest();
        }
        catch(e)    {       
            try{            
                xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
            }
            catch(e){
                try{
                xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                }
                catch(e1){
                    xmlhttp=false;
                }
            }
        }

        return xmlhttp;
    }


 function getCity(str)
 {
 //alert(str);
 var xmlhttp;
 if (str=="")
   {
   document.getElementById("citydiv").innerHTML="";
   return;
   }
 if (window.XMLHttpRequest)
   {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
   }
 else
   {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
 xmlhttp.onreadystatechange=function()
   {
   if (xmlhttp.readyState==4 && xmlhttp.status==200)
     {
     document.getElementById("citydiv").innerHTML=xmlhttp.responseText;
     }
   }
 xmlhttp.open("GET","wamp/www/daftar lewat/cawangan.php?id_negeri="+str,true);
 xmlhttp.send();
 }
</script>



<style type="text/css">
<!--
.style1 {
    font-weight: bold;
    font-size: x-large;
}
.style5 {
    font-family: Arial, Helvetica, sans-serif;
    font-size: larger;
}
.style8 {font-weight: bold; font-family: "Britannic Bold"; font-size: large;}
-->
</style>

</head>
<body>
<<form id="form1" name="form1" method="post" action="prosescubaan.php" >

  <table width="673" height="694" border="5" align="center" bordercolor="#D0F0C0">
    <tr>

      <td width="655" bgcolor="#D0F0C0"><table width="641" height="686" border="0" align="left" cellspacing="0">
        <tr>
          <td height="195" colspan="5"><img src="images/JPN2.jpg" width="641" height="195" /></td>
        </tr>
        <tr>


          <td height="32" bgcolor="#D0F0C0" class="style21">&nbsp;</td>
     <td colspan="4" bgcolor="#D0F0C0" class="style24"><div align="right">
                <script language="javascript" src="Calender4/cal2.js"></script>
                <script language="javascript" src="Calender4/cal_conf2.js"></script>
                <script language=JavaScript>



                <!-- begin script
                function MakeArray(n) {
                this.length=n;
                for (var i=0; i <= N; I++) {
                this[i]='0' }
                return this
                }

                function display_date() 
                {            
                date=new Date();
                var day_of_week_number=date.getDay();
                var day_of_month=date.getDate();
                var month_number=date.getMonth();
                var year=date.getFullYear();
                var day_of_week='';
                var month=''

                if(month_number == 0){month='Januari';}
                if(month_number == 1){month='Februari';}
                if(month_number == 2){month='Mac';}
                if(month_number == 3){month='April';}
                if(month_number == 4){month='Mei';}
                if(month_number == 5){month='Jun';}
                if(month_number == 6){month='Julai';}
                if(month_number == 7){month='Ogos';}
                if(month_number == 8){month='September';}
                if(month_number == 9){month='Oktober';}
                if(month_number == 10){month='November';}
                if(month_number == 11){month='Disember';}

                var date_to_show=day_of_month + ' ' + month + ' ' + year;
                document.write(date_to_show);
                }
                document.write
                  display_date()
                  //-->            
                      </script>
                -     
                <script language=JavaScript>

                <!-- begin script
                function papar_hari() {
                var day_of_week_number=date.getDay();
                var day_of_week='';
                if(day_of_week_number == 0){day_of_week='Ahad';}
                if(day_of_week_number == 1){day_of_week='Isnin';}
                if(day_of_week_number == 2){day_of_week='Selasa';}
                if(day_of_week_number == 3){day_of_week='Rabu';}
                if(day_of_week_number == 4){day_of_week='Khamis';}
                if(day_of_week_number == 5){day_of_week='Jumaat';}
                if(day_of_week_number == 6){day_of_week='Sabtu';}

                document.write(day_of_week);
                }
                document.write
                  papar_hari()
                  //-->            
                      </script>


                - <?php echo date("H : i : s A"); ?> 

    </div>   </td>
    </tr>

    <tr>
    <td bgcolor="#FFCCCC" class="style21">&nbsp;</td>
     <td colspan="4" bgcolor="#FFCCCC"  align="left"><b>
     <?php
        //  $logid= $_SESSION['LOG_ID'];

            $sql4 = "SELECT * FROM login2 WHERE no_kpt = '".$_SESSION['ic']."'";
            $result4 = mysql_query($sql4);
            $row4 = mysql_fetch_array ($result4);

            $nama = $row4['nama'];

    ?>
            NAMA PEGAWAI
            ::
            <?php echo $nama; ?></b></td>

 </tr>


     <td colspan="4" bgcolor="#D0F0C0"  align="left">
        <tr>
          <td height="29" bgcolor="#D0F0C0" class="style21">&nbsp;</td>
          <td colspan="4" bgcolor="#D0F0C0" class="style24" align="left"><b><a href="login.php">[ &lt;&lt; KEMBALI ]</a></b></td>
        </tr>
        <tr valign="top">
          <td width="2" rowspan="30" bgcolor="#D0F0C0" ></td>
          <td colspan="4" bordercolor="#D0F0C0" bgcolor="#D0F0C0"><div align="center" class="style1 style5">DAFTAR LEWAT KAD PENGENALAN</div></td>
        </tr>
        <tr>
          <td width="5" height="21" bgcolor="#D0F0C0" class="style21">&nbsp;</td>
          <td colspan="4" bgcolor="#D0F0C0" class="style24"><hr align="center" noshade="noshade" class="tiny" /></td>
        </tr>
        <tr>
          <td height="21" bgcolor="#99E6B3" class="style21">&nbsp;</td>
        <td colspan="4"  align="left" bordercolor="#999933" bgcolor="#99E6B3"><div align="center" class="style8"><u> MAKLUMAT PERMOHONAN </u></div></td>
        </tr>
        <tr>
          <td height="21" bgcolor="#D0F0C0" class="style21"></td>
          <td width="163" bgcolor="#D0F0C0" class="style21"><div align="left"><strong>Negeri</strong></div></td>
          <td width="7" bgcolor="#D0F0C0" class="style21"><b>:</b></td>
          <td width="456" bgcolor="#D0F0C0"><select name="negeri" onChange="getCity(str)">

        <?php 
   // $Type_sql = "SELECT negeri FROM negeri ORDER by negeri_id  ASC ";
    $Type_result = mysql_query( "SELECT negeri FROM negeri ORDER by negeri_id ASC" );

   if(!isset($chkvalue))
                    { 
                        echo "<option value=''>Sila Pilih</option>";

    while ( $Type_rows = mysql_fetch_array($Type_result) ) {
        //echo '<option value="'.$Type_rows['negeri_id']. '" > '.$Type_rows['negeri'].'  </option>';

         echo "<option value= '".$Type_rows['kod_negeri']."'  >  '".$Type_rows['negeri']."'  </option>";
         echo "".$Type_rows["kod_negeri"]."  &nbsp; ".$Type_rows["negeri"]."" ; 

         //  echo "<option value='".$Type_rows["kod_negeri"]."' > '".$Type_rows["negeri"]."'>";

    }
    }
    ?>
</select>

                </td>
        </tr>
        <tr>
          <td height="21" bgcolor="#D0F0C0" class="style21"></td>
          <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Cawangan</b></div></td>
          <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
          <td bgcolor="#D0F0C0" <div id="citydiv"><select name="cawangan">
           </div>

        <?php 
   // $Type_sql = "SELECT cawangan FROM negeri_cawangan ORDER by negeri_id  ASC ";
    $Type_result = mysql_query( "SELECT cawangan FROM negeri_cawangan ORDER by negeri_id ASC" );

   if(!isset($chkvalue))
                    { 
                        echo "<option value=''>Sila Pilih</option>";

    while ( $Type_rows = mysql_fetch_array($Type_result) ) 
    {
        //echo '<option value="'.$Type_rows['negeri_id']. '" > '.$Type_rows['negeri'].'  </option>';

         echo "<option value= '".$Type_rows['kod']."'  &&   '".$Type_rows['cawangan']."'  >";
         echo "".$Type_rows["kod"]."  &nbsp; ".$Type_rows["cawangan"]."" ; 

         //  echo "<option value='".$Type_rows["kod_negeri"]."' > '".$Type_rows["negeri"]."'>";

    }
    echo "</option>";
    }
                    else 
                    { 
                        echo "<option value=''>---</option>";
                    }

                    echo "</select>";
    ?>
        </tr>



        <tr>

          <td height="24" bgcolor="#D0F0C0" class="style21"></td>
          <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Tarikh Permohonan </b></div></td>
          <td bgcolor="#D0F0C0" class="style21"><strong>:</strong></td>
          <td bgcolor="#D0F0C0"><input name="tarikh_permohonan1" type="text" id="tarikh_permohonan1" />
              <small> <a href="javascript:showCal('Calendar4')"></a></small> format : dd-mm-yyy </td>
        </tr>
        <tr>
          <td height="24" bgcolor="#D0F0C0" class="style21"></td>
          <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Tarikh Surat Cawangan </b></div></td>
          <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
          <td bgcolor="#D0F0C0"><input name="tarikh_suratcawangan" type="text" id="tarikh_suratcawangan" />
            <small> <a href="javascript:showCal('Calendar4')"></a></small> format : dd-mm-yyy  </td>
        </tr>
        <tr>
          <td height="24" bgcolor="#D0F0C0" class="style21"></td>
          <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Tarikh Surat </b></div></td>
          <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
          <td bgcolor="#D0F0C0"><input name="tarikh_surat" type="text" id="tarikh_surat" />
              <small> <a href="javascript:showCal('Calendar4')"></a></small> format : dd-mm-yyy           </td>
        </tr>


 <td height="30" bgcolor="#D0F0C0" class="style21">&nbsp;</td>
          <td colspan="4" bgcolor="#D0F0C0" class="style24"><hr align="center" noshade="noshade" class="tiny" /></td>
        </tr>

     <tr>
          <td height="21" bgcolor="#99E6B3" class="style21">&nbsp;</td>
          <td colspan="4"  align="left" bordercolor="#999933" 

bgcolor="#99E6B3"><div align="center" class="style8"> <u>MAKLUMAT PEMOHON</u></div></td>
        </tr>

  <tr>
    <td height="24" bgcolor="#D0F0C0" class="style21"></td>
    <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Nama Pemohon</b></div></td>
    <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
    <td bgcolor="#D0F0C0"><input name="NAMA_PEMOHON" type="text" size="40" id="NAMA_PEMOHON" /></td>
  </tr>

  <tr>
    <td height="24" bgcolor="#D0F0C0" class="style21"></td>
    <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>No. KPT Pemohon</b></div></td>
    <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
    <td bgcolor="#D0F0C0"><input name="IC2" type="text" size="40" id="IC2" /></td>
  </tr>



 <td bgcolor="#D0F0C0" class="style21">&nbsp;</td>
          <td colspan="4" bgcolor="#D0F0C0" class="style24"><hr align="center" noshade="noshade" class="tiny" /></td>
        </tr>


     <tr>
          <td height="21" bgcolor="#99E6B3" class="style21">&nbsp;</td>
          <td colspan="4"  align="left" bordercolor="#999933" bgcolor="#99E6B3"><div align="center" class="style8"> <u>MAKLUMAT PEGAWAI </u></div></td>
        </tr>  


    <td height="47" bgcolor="#D0F0C0" class="style21"></td>

    <td bgcolor="#D0F0C0" class="style21"><div align="left"><b>Nama Pegawai </b></div></td>
    <td bgcolor="#D0F0C0" class="style21"><b>:</b></td>
    <td bgcolor="#D0F0C0"> <?php
                echo "<select name='NAMA_PEGAWAI'>";

                    //Starts of first drop downlist
                    if(!isset($chkvalue))
                    { 
                        echo "<option value=''>Sila Pilih</option>";

                        //Starts of first drop downlist
                        $sql = mysql_query("SELECT * FROM pegawai_dlkp order by nama_pegawaidlkp") 
                        or die(mysql_error()); 

                        while ($row = mysql_fetch_array($sql))
                        {
                            echo "<option value='".$row["nama_pegawaidlkp"]."'>";
                            echo $row["nama_pegawaidlkp"]; 
                        }
                        echo "</option>";
                    }
                    else 
                    { 
                        echo "<option value=''>---</option>";
                    }

                    echo "</select>";
                    ?></td>
    </tr>

  <tr>
          <td height="21" bgcolor="#D0F0C0" class="style21">&nbsp;</td>
          <td colspan="4"  align="left" bordercolor="#999933" bgcolor="#D0F0C0"><div align="center" class="style8">
            <label></label>
            <table width="614" border="1">
              <tr>
                <th width="267" scope="col"><input type="reset" name="Submit2" value="PADAM" /></th>
                <th width="331" scope="col"><input type="submit" name="Submit" value="SETERUSNYA" /></th>
              </tr>
            </table>
          </div></td>
        </tr>

  <tr>
    <td colspan="4" bgcolor="#29AB87"><div align="center"><span class="style21">JABATAN PENDAFTARAN NEGARA 2014</span></div></td>
  </tr>
      </table></td>
    </tr>
  </table>

</form>
</body>

</html>

Next is my code for cawangan.php :

<? 
$link = mysql_connect("localhost", "root", ""); //changet the configuration in required
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("smile");


isset($_REQUEST['negeri_id']) ? $negeri_id = $_REQUEST['negeri_id'] : $negeri_id = '2';

$query = "SELECT * FROM negeri_cawangan WHERE negeri_id = $negeri_id ";
$result=mysql_query($query);

?>



<select name="negeri" onchange='getSeksyen(this.value)'>
<option> Negeri</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option  value="<?=$row['negeri_id']?>"><?=$row['negeri']?></option>
<? } ?>
</select>

This code check for SPACE in value:

document.form1.NEGERI.value==' '

but this check for empty value:

document.form1.NEGERI.value==''
Member Avatar for diafol

dokument -> document?

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.