0

Hi

I am trying to clone a row with dependent dropdown. first row is working fine. Once i click add row button, if i select the project option its not working on client select option.

can anyone please help me to fix.

Note: I used trying using id="client[]" and id="project[]" is not working

do-de.php

<?php
    session_start();
    include("myDB.php");
?>
<!DOCTYPE html>
<html>
<head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title> - jsFiddle demo</title>


  <script type='text/javascript' src='//code.jquery.com/jquery-1.9.1.js'></script>




  <link rel="stylesheet" type="text/css" href="/css/result-light.css">

  <style type='text/css'>

  </style>


<script type='text/javascript'>//<![CDATA[
jQuery(function($){
    var $button = $('#add-row'),
        $row = $('.timesheet-row').clone();

    $button.click(function(){
        $row.clone().insertBefore( $button );
    });
});

$(document).ready(function(){


               $("#client").change(function(){
                     var client=$("#client").val();
                     $.ajax({
                        type:"post",
                        url:"getproject.php",
                        data:"client="+client,
                        success:function(data){
                              $("#project").html(data);
                        }
                     });
               });
           });

</script>

</head>
<body>
<fieldset id="timesheet-rows">
    <legend>Add Entries</legend>

    <div class="timesheet-row">

        <label>Client:
            <select name="client[]" id="client" required>
            <option value="">-- Please Select Client--</option>
                <?php 
                    $hrdep = mysql_query("select distinct(client_name) from ce_client order by client_id asc"); 
                    while($hrres = mysql_fetch_array($hrdep)){ ?>
                    <option value="<?php echo $hrres['client_name']; ?>"><?php echo $hrres['client_name']; ?></option>
                <?php } ?>
            </select>
        </label>

        <label>project:
            <select name="project[]" id="project" required>
                <option>-select your project-</option>
            </select>
        </label>

        <label>Task: 
            <select name="task[]" required>
            <option value="" />
            </select>
        </label>

        <label>Hours:
            <input type="number" step="0.25" name="hours[]" width="1" placeholder="2.0" required />
        </label>

        <label>Comment:
            <input type="text" name="comment[]" width="50" />
        </label>

    </div>

    <input type="button" id="add-row" name="add-row" value="Add row" />
</fieldset>

</body>

</html>

getproject.php

<?php
  include("myDB.php");

 $client=$_POST["client"];
  $result=mysql_query("select * FROM ce_client where client_name='$client' ");
  while($project=mysql_fetch_array($result)){
    echo"<option value=$project[client_project]>$project[client_project]</option>";

  }
?>
Attachments screen.jpg 35.41 KB
2
Contributors
1
Reply
9
Views
2 Years
Discussion Span
Last Post by diafol
0

I've only just scanned this quickly, but you can't have "array-type" ids as you would name attributes.
ALso why using depracted mysql_* functions? mysqli or PDO should be used. You are open to SQL injection because you do not sanitize your input. If you use prepared statements, this is not a problem.
If you're retrieving data, we usually use GET not POST.

This topic has been dead for over six months. 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.