0

So i got one form so the user can enter and submit their personal details. The problem is i didn't apply any validation . I've done a simple validation like this , but it seem to be not working .

function validate(){
    if((\$('txt_no_kp').value != '') && (\$('txt_nama').value != '') && (\$('txt_alamat').value != '')){
        \$('btn_basic').disabled = false;
    }
    else{
        \$('btn_basic').disabled = true;
    }
}

Please help me out . I've read some tutorial for form validation, but i don't understand it quite well . This is my form code . Sorry for my bad english though ..

<p><a href="borang_pencarikerja.php">Tambah Pencari Kerja Baru</a>&nbsp;<a href="borang_pencarikerja.php"><img src="images/add_16.png" width="16" height="16" border="0" align="absbottom" /></a></p>
<form action="simpan_jobseeker.php" method="post" enctype="multipart/form-data" name="function_search_form" id="function_search_form" class="search_form">
<?php echo $inp; ?>
<table border="0" cellpadding="3" cellspacing="2">
<tr><td align="left" valign="top">
  <table width="592" border="0">
    <tr>
      <td colspan="2"><em><strong>Maklumat Pencari Kerja</strong></em></td>
    </tr>
    <tr>
      <td colspan="2"><strong>No KP</strong>
        <input type="text" name="txt_no_kp" id="txt_no_kp" value="<?php echo $no_kp; ?>" onchange="validate()" />
        <div id="autocomplete_no_kp" class="autocomplete"></div>      </td>
    </tr>
    <tr>
      <td colspan="2"><strong>Sumber</strong>
        <div id="div_sumber"><select name="txt_sumber" id="txt_sumber">
          <option>Sila Pilih</option>
<?php
    $sql = "SELECT * FROM lstsumber ORDER BY nama ASC";
    $res_sumber = mysql_query($sql);
    while($row_sumber = mysql_fetch_array($res_sumber)){
?>        
          <option value="<?php echo strtolower($row_sumber['nama']); ?>"><?php echo ucwords(stripslashes($row_sumber['nama'])); ?></option>
<?php
    }
?>
        </select></div>
        </td>
    </tr>
    <tr>
      <td colspan="2"><strong>Nama</strong>
        <div id="div_nama"><input name="txt_nama" type="text" id="txt_nama" onchange="validate()" size="40" />
        </div>      </td>
    </tr>
    <tr>
      <td colspan="2"><strong>Alamat</strong><br />
        <div id="div_alamat"><textarea name="txt_alamat" id="txt_alamat" cols="40" rows="3" onchange="validate()"></textarea></div>      </td>
    </tr>
    <tr>
      <td><strong>Poskod</strong> 
        <div id="div_poskod"><input type="text" name="txt_poskod" id="txt_poskod" /></div>
        <div id="autocomplete_poskod" class="autocomplete"></div>        </td>
      <td><strong>Daerah</strong>
        <div id="div_daerah"><input type="text" name="txt_daerah" id="txt_daerah" /></div>
        <div id="autocomplete_daerah" class="autocomplete"></div>        </td>
    </tr>
    <tr>
      <td colspan="2"><strong>Negeri</strong>
        <div id="div_negeri"><input type="text" name="txt_negeri" id="txt_negeri" /></div>
        <div id="autocomplete_negeri" class="autocomplete"></div></td>
    </tr>
    <tr>
      <td><strong>No Tel Bimbit</strong>
        <div id="div_tel_bimbit"><input type="text" name="txt_tel_bimbit" id="txt_tel_bimbit" /></div>      </td>
      <td><strong>No Tel Rumah</strong>
        <div id="div_tel_rumah"><input type="text" name="txt_tel_rumah" id="txt_tel_rumah" /></div></td>
    </tr>
    <tr>
      <td colspan="2">       </td>
    </tr>
    <tr>
      <td colspan="2"><strong>Email</strong>
        <div id="div_email"><input type="text" name="txt_email" id="txt_email" /></div>      </td>
    </tr>
    <tr>
      <td><strong>Jantina</strong>
        <div id="div_jantina">
        <select name="txt_jantina" id="txt_jantina">
          <option>Sila Pilih</option>
<?php
    $sql = "SELECT * FROM lstjantina ORDER BY nama ASC";
    $res_jan = mysql_query($sql);
    while($row_jan = mysql_fetch_array($res_jan)){
?>        
          <option value="<?php echo strtolower($row_jan['nama']); ?>"><?php echo ucwords(stripslashes($row_jan['nama'])); ?></option>
<?php
    }
?>
        </select>
      </div></td>
      <td><strong>Status</strong>
        <div id="div_status">
        <select name="txt_status" id="txt_status">
          <option>Sila Pilih</option>
<?php
    $sql = "SELECT * FROM lststatus ORDER BY nama ASC";
    $res_status = mysql_query($sql);
    while($row_status = mysql_fetch_array($res_status)){
?>        
          <option value="<?php echo strtolower($row_status['nama']); ?>"><?php echo ucwords(stripslashes($row_status['nama'])); ?></option>
<?php
    }
?>
        </select>
        </div></td>
    </tr>
    <tr>
      <td colspan="2"><strong>Status Pekerjaan Calon</strong>
        <div id="div_status_kerja">
    <select name="txt_status_kerja" id="txt_status_kerja">
          <option>Sila Pilih</option>
<?php
    $sql = "SELECT * FROM lststatus_kerja ORDER BY nama ASC";
    $res_status2 = mysql_query($sql);
    while($row_status2 = mysql_fetch_array($res_status2)){
?>        
          <option value="<?php echo strtolower($row_status2['nama']); ?>"><?php echo ucwords(stripslashes($row_status2['nama'])); ?></option>
<?php
    }
?>
    </select>
    </div></td>
    </tr>
    <tr>
      <td colspan="2"></td>
    </tr>
    <tr>
      <td colspan="2"><strong>Resume </strong>        
        <div id="div_filename"><input name="upresume" type="file" id="upresume" size="40" />
        </div>
      </td>
    </tr>
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
  </table>
  </td></tr>
  <tr><td align="center" valign="middle">
  <input type="submit" name="btn_basic" id="btn_basic" value="Simpan" disabled="disabled" />
    </td></tr>
    </table>
</form><br />
3
Contributors
3
Replies
32
Views
3 Years
Discussion Span
Last Post by nazree.zeko
0

I would agree use jquery library to make things simple.

but the looks of you validation function why do you have '\' backslash.. are you tring to escape something.. I think you might be confussed.

Most browsers will except required="required" in the input elements now. This will check if the input is empty or not.

<input type="text" name="name" value="" placeholder="" required="required" />

0

thanks for the reply , i'll already search & explore the link u gave me Tpojka . But , honestly i didn't quite understand fully about jquery . I'll try my best

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.