0

Im getting a error "TypeError: autocomplete is not a function" while running my autocompletion form. This is my html code:

<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Track and Trace</title>
        <link href="js/jquery.mobile.theme-1.3.0.css" rel="stylesheet" type="text/css" />
        <link href="js/jquery.mobile.structure-1.3.0.css" rel="stylesheet" type="text/css" />
        <script src="js/cordova-2.4.0.js"  type="text/javascript"></script> 
        <script src="js/jquery-1.6.4.min.js" type="text/javascript"></script>
        <script src="js/jquery.mobile-1.3.0.min.js" type="text/javascript"></script>
        <script src="js/status.js" type="application/javascript"></script>
</head>
<body>
<div data-role="content"  style=" margin-top:1%; margin-bottom:10%;" align="center"> <!--Content-->
                <div class="frmSearch" style="width:75%" align="center">
                <div class="input_container">
                    <input type="text" name="jobno" id="jobno" onkeyup="autocomplete()" value=""  placeholder="Job No "  data-theme="a"/>
                    <ul id="jobno_list"></ul>
                    <input type="text" name="jobseq" id="jobseq" value="" placeholder="Job Seq No"  data-theme="a" />
                    <input type="text" name="status" id="status" value="" placeholder="Status"  data-theme="a"/>
                    <input type="text" name="remarks" id="remarks" value="" placeholder="Remarks"  data-theme="a"/>
                    <button onClick="javascript: validate(); " >Save</button>
                    <button type="reset" onClick="javascript: reset(); " >Reset</button>
                </div>
            </div>
                </div>


</body>
</html>

JavaScript Function:

function autocomplete() {
    var min_length = 0; // min caracters to display the autocomplete
    var keyword = $('#jobno').val();
    if (keyword.length >= min_length) {
        $.ajax({
            url: '192.168.0.102/ipack/refresh.php',
            type: 'POST',
            data: {keyword:keyword},
            success:function(data){
                $('#jobno_list').show();
                $('#jobno_list').html(data);
            }
        });
    } else {
        $('#jobno_list').hide();
    }
}

And following is my php file:

<?php
    header('Access-Control-Allow-Origin: *');
    include 'dbconnection.php';

    $keyword = '%'.$_POST['keyword'].'%';
    $sql = "SELECT JOBNO FROM PRTJOBHD WHERE JOBNO LIKE (:keyword) ORDER BY JOBNO ASC";
    $query = $pdo->prepare($sql);
    $query->bindParam(':keyword', $keyword, PDO::PARAM_STR);
    $query->execute();
    $list = $query->fetchAll();
    foreach ($list as $rs) {
    // put in bold the written text
    $jobno = str_replace($_POST['keyword'], '<b>'.$_POST['keyword'].'</b>', $rs['JOBNO']);
    // add new option`enter code here`
    echo '<li onclick="set_item(\''.str_replace("'", "\'", $rs['JOBNO']).'\')">'.$jobno.'</li>';
?>

Can anyone help me out of this. thanks in advance.

Vipin KA
  • 33
  • 1
  • 12
  • missing the `http://` from `url: '192.168.0.102/ipack/refresh.php',` and i doubt if you can access `html` data cross domain. you can take a look into `jsonp`. – Jai Sep 17 '15 at 08:49
  • It looks to me like we're missing some code -- I can't see where you're trying to call autocomplete(). – Matt Parlane Sep 17 '15 at 08:53
  • In what file is `autocomplete` function? Is that file added to html? – Stubb0rn Sep 17 '15 at 09:27
  • No. Its in js file. – Vipin KA Sep 17 '15 at 09:29
  • It doesn’t work because the `onkeyup` attribute assumes an implicit `with`-scope that includes the element’s prototype which contains the string getter property `autocomplete` from `HTMLInputElement.prototype.autocomplete`, overriding the `autocomplete` function defined above. Which, by the way, is one of [_many_ reasons to avoid `onkeyup`](https://stackoverflow.com/a/43459991/4642212). – Sebastian Simon Aug 14 '19 at 18:37
  • Possible duplicate of [JS function named \`animate\` doesn't work in Chrome, but works in IE](https://stackoverflow.com/questions/28173800/js-function-named-animate-doesnt-work-in-chrome-but-works-in-ie) – Sebastian Simon Aug 14 '19 at 18:38

0 Answers0