0

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

Community
  • 1
  • 1
Arif
  • 1,222
  • 6
  • 29
  • 60
  • What is the problem? the function doesn't be called? try to use the 'select' in the autocomplete function. – Hadas Mar 26 '12 at 12:25
  • @Hadas yes the function doesn't be called, & i try keypress & other events also but none of them works – Arif Mar 26 '12 at 12:28

1 Answers1

1

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

Milindu Sanoj Kumarage
  • 2,714
  • 2
  • 31
  • 54
  • your function is called when you finished typing and get out of the text box. But in my case i just enter **a** and all product containing a displayed to me & then i click on my desired one – Arif Mar 26 '12 at 12:55