0

So i want use 2 function java Script for automatically add the new column when the contents and autosuggestion, this for example coding automatically add the new column when the contents http://jsfiddle.net/3jLbm9sp/1/ so when i try input in first column, he will be give auto suggestion for first column and add new column(second column) and give autosuggestion too. but i cant This is all my coding :

<html>
    <head>
        <form method = "POST" action="text.php" >
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Admin</title>
        <link href="css/inputpo.css" rel="stylesheet">
        <link rel="stylesheet" href="css/jquery-ui.css"/>
        <script src="js/jquery-1.9.1.js"></script>
        <!--For Auto Suggestion -->
        <script src="js/jquery-ui.js"></script>
        <script type="text/javascript">
        $(document).ready(function(){
            $("#code1").autocomplete({
                source: 'autosuggest.php',
                select:function(event, ui){
                            $('#descrip1').val(ui.item.descrip1);                           
                }
            });
        });
        </script>
        <!--For Auto Add New Colomun-->
        <script type="text/javascript">
        var data = <?php echo json_encode($code1); ?>;
            $txt=new Array();
            $(function(){
                $('#go').on('click',function(){
                    console.log($('form').serialize());
                })

                $('body').on('keydown','.last',function(){
                    $('.last').removeClass('last');
                    $('#go','body').before(
                    '<table><tr><td><input class="last" type="text" id="code1" name="code'+(Number($(this).attr('name').match(/[0-9]+/g))+1)+'" value=""></td>

');
}) })

    </head>
    <body>
    <?php
$code1="";
if($_GET) {
$code1      = isset($_POST['code']) ? $_POST['code1'] : '';
$descrip    = isset($_POST['descrip1']) ? $_POST['descrip1'] : '';

}
?>
        <div class="isi">
                <table height="51" border="0" cellspacing="2">
                <tr>
                    <td width="99" align="center" label for="suggestionbox">
                        <div align="center">Code</div></label>
                    </td>
                    <td>
                        <div align="center">Description</div>
                    </td>
              </tr>
              <tr>
                <td>
                <input  class="last"  type="text" id="code1" name='code1' value="<?php echo $code1;?>">
                </td>
                <td>
                <input  class="last"  type="text" id="descrip1" name='descrip1' value="">
                </td>
              </tr>
            </table>
                <input id="go" name="" type="submit" /></td>
        </div>
    </body>
</html>

if i only use autosuggestion it's work but cant add new column, and if i use add new column, I can not get auto suggestion, when i check the fail Function is in here

type="text" id="code1" name="code'+(Number($(this).attr('name').match(/[0-9]+/g))+1)+'" value="">

if value is empty ="" its work for add new column,and where for autosuggestion variable (PHP) is $code1, so i try write in value=""> does anybody know how to write php variable inside a javascript function? can use another like ajax, but i don't know how.

2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.