Arif
Arif

Reputation: 1211

jQuery Trigger onKeyup Event

I have a SELECT LIST MENU containing products and on this menu i use onChangeevent. when you select any product, it load company name of that product.Below is the function which i used,

function getcompany(element) {        

        var strURL="getcompany.php?product="+element.value; 
        var req = getXMLHTTP();

        if (req) {

            req.onreadystatechange = function() {
                if (req.readyState == 4) {
                    // only if "OK"
                    if (req.status == 200) {   

                        element.parentNode.parentNode.getElementsByClassName('companydiv')[0].innerHTML=req.responseText;                       
                    } else {
                        alert("There was a problem while using XMLHTTP:\n" + req.statusText);
                    }
                }               
            }           
            req.open("GET", strURL, true);
            req.send(null);
        }       
    }

And my html code is,

<select name="product" onChange="getcompany(this)">
    <option value="1" >Product1</option>
    <option value="2" >Product2</option>
    </select>
    <div class="companydiv">Product result will be shown here</div>

The above code work but now i want to use jquery autocomplete instead of SELECT LIST MENU because my product list containing more then 1000 products.

My Autocomplete code is,but i dont know where i'm wrong

<input name="product" id="product" type="text" onkeyup="getcompany(this)" />

Some other answers i already checked but i'm not satisfied with anyone, some of them are below

jQuery AutoComplete Trigger Change Event

Jquery Autocomplete onChange event

http://forum.jquery.com/topic/autocomplete-and-change-event

Upvotes: 0

Views: 1689

Answers (1)

Milindu Sanoj Kumarage
Milindu Sanoj Kumarage

Reputation: 2774

I could not find your error here, however I could make what you are trying to do. I used jquery here. jsFiddle

Upvotes: 1

Related Questions