0

I'm using onClick() method to call a function when html select option is change. It's working fine in Mozila Firefox but why it's not working on Chrome Broser ?

<select name="project_list" class="project_list">
    <option>--Select Project--</option>        
    <?php 
    $getProjectList = mysqli_query($link, "SELECT p_id, p_name FROM projects WHERE p_owner_id = '$logged_user_id' ");
    while($list=mysqli_fetch_array($getProjectList)){
        $list_p_id = $list['p_id'];
        $list_p_name = $list['p_name'];
      ?>
        <option onclick="showProjectDetails(<?php echo $list_p_id; ?>);"><?php echo $list_p_name; ?></option>";
    <?php
    }
    ?> 

Note : This onclick() method get the id value from html option change and pass to showProjectDetails()

Update :

<table border="0" cellpadding="0" cellspacing="0" width="570">
<tr>
  <td width="142">Project</td> 
  <td><input type="text" id="project_name" name="p_name" value="<?php echo $p_name; ?>" /></td>
    <td colspan="1" align="right">
    <select name="project_list" class="project_list">
      <option>--Select Project--</option>  
      <?php 
      $getProjectList = mysqli_query($link, "SELECT p_id, p_name FROM projects WHERE p_owner_id = '$logged_user_id' ");
      while($list=mysqli_fetch_array($getProjectList)){
          $list_p_id = $list['p_id'];
          $list_p_name = $list['p_name'];
          ?>
          <option onclick="showProjectDetails(<?php echo $list_p_id; ?>);"><?php echo $list_p_name; ?></option>";
          <?php
      }
      ?> 
    </select>
    </td>
    <td>
      <a href="#" class="normalSearch">Normal Search</a> <br> <a href="#" class="advanceSearch">Advanced search</a>
    </td>
</tr>
<tr>  
  <td width="142">For</td> 
  <td colspan=""><input type="text" id="project_company" name="company_name" value="<?php echo $p_c_name; ?>" /></td>
  <td></td>  
</tr>
</table>

Update 2 :

function showProjectDetails(e){
var id = $(e).val();
$.ajax({
type:"post",
url:"showProjectDetails.php",
data:"id="+id,
    success:function(res){        
        $('#showProjectForm').html(res);        
    }
}); 
}
Shibbir
  • 1,963
  • 2
  • 25
  • 48

2 Answers2

3

I don't think <option> elements can receive clicks. See this fiddle. Clicking the options doesn't make anything.

You want to watch changes on the <select> element:

$('select.project_list').on('change', function() {
  alert( this.value ); // or $(this).val()
});
Jeremy Thille
  • 26,047
  • 12
  • 43
  • 63
1

You need to attach the function to your select tag rather than to your option tag . Try this:

<select name="project_list" class="project_list" onchange="showProjectDetails(this);">
    <option>--Select Project--</option>        
    <?php
    $getProjectList = mysqli_query($link, "SELECT p_id, p_name FROM projects WHERE p_owner_id = '$logged_user_id' ");
    while ($list = mysqli_fetch_array($getProjectList)) {
        $list_p_id = $list['p_id'];
        $list_p_name = $list['p_name'];
        ?>
        <option value="<?php echo $list_p_id; ?>"><?php echo $list_p_name; ?></option>";
        <?php
    }
    ?> 
</select>
<script>
    function showProjectDetails(e) {
        var val = $(e).val();
        alert(val);
    }
</script>
CodeGodie
  • 12,116
  • 6
  • 37
  • 66