0

I met some trouble with my code,

In fact I would like to replace words abreviation by their expressions, but it does not work.

I have done the following code:

<script>
    $('#suivi').keyup(function (e) {
        var code = e.which ? e.which : e.keyCode;
        var input = this.value;
        console.log(input);
        <?php
            $rqt = "SELECT * FROM `glossaire` WHERE `id_company` ='".$societe['id']."'";
            $result = mysql_query($rqt);
            while ($data = mysql_fetch_assoc($result)) {
        ?>
                if (input == "<?php echo ($data['libelle']) ; ?>") {
                    this.value = "<?php echo ($data['texte']) ; ?>"
                };
        <?php
            }
        ?>      
   });
</script>

jquery 1.8 is set up on my page.

This script works fine on the following jsfiddle:

http://jsfiddle.net/3z3sP/1/

But not in my page. However it is the same.

I have no mistakes in the console of javascript.

Any kind of help will be much appreciated.

Kind regards.

SP.

4

1 回答 1

2

The jsfiddle works fine for me. I think your code is being executed before the #suivi is found. Try wrapping the script in $(function(){}):

<script>

    $(function()
    {

        $('#suivi').keyup(function(e){
        var code = e.which ? e.which : e.keyCode;
        var input = this.value;
        console.log(input);
      <?php $rqt="SELECT * FROM `glossaire` WHERE `id_company` ='".$societe['id']."'";
    $result=mysql_query($rqt);
    while($data=mysql_fetch_assoc($result))
    {?>
        if (input == "<?php echo ($data['libelle']) ; ?>") {
           this.value = "<?php echo ($data['texte']) ; ?>"

        };
     <?php } ?>      
    });

    });

</script>
于 2012-10-31T10:32:38.670 回答