Hey Peeps!

been doing a bit of jquery latley and decided to implement some into my live site,

now i know this is probably the most basic thing that i am missing, but i need some sort of stop() in my code, thing is, im not too sure where to put it when it comes to ajax.

$('#company').onblur(function(){
            $('#getcon').append('<img src="../img/loading.gif" id="loading" alt="loading" />');
                var comID = $('#company').val();
               
                $.ajax({
                    url : 'getcon.php',   
                    type : 'POST', 
                    data: 'comID=' + comID,
                    success : function(result){
                        $('#response').remove();
                        $('#getcon').append(result);
                        $('#loading').fadeOut(500,function(){
                        $(this).remove();
                    });
                    return false;
                   }
                   
                  });
                 });

that is my jquery to a php file which retrieves a
<select></select> with the options that are 100% spot on, only thing is that it keeps appending selects everytime i click/keydown/blur.

Hope this is all readable and im making sense :)

any help will be greatly appreciated! :)

Recommended Answers

All 2 Replies

Member Avatar for stbuchok

If you don't want it to append, then don't append it, correct?

Are you looking to fill the dropdownlist, add new items to the dropdown list, create multiple dropdownlists?

You specifically told it to append, so I'm a little confused as to what you need.

hey stbuchok

i have added $('.contacts').remove(); after the $('#company').keydown(function(){

basically all i want is:

i have a company list of 36 000 companies, within those companies i have on average 3-7 people. so i want jquery to let me chooses the company name the retrieve the contacts list from the specific company.

its doing it ok now that i have added the remove(); but im pretty sure that im not doing it right :).

Here is the new code:

$('#company').keydown(function(){
            $('.contacts').remove();
            $('#getcon').append('<img src="../img/loading.gif" id="loading" alt="loading" />');
                var comID = $('#company').val();
               
                $.ajax({
                    url : 'getcon.php',   
                    type : 'POST', 
                    data: 'comID=' + comID,
                    success : function(result){
                        $('#response').remove();
                        $('#getcon').append(result);
                        $('#loading').fadeOut(500,function(){
                        $(this).remove();
                    });
                    return false;
                   }
                   
                  });
                 });

and then the getcon.php

<?php
include_once ('TBS/stuff.php');
$conn = db_connect();

$response = $_POST['comID'];
$query_contact = mysql_query("SELECT contact_name, ContactID, first_name, last_name FROM ct_tbl WHERE acomID = {$response}");
  echo "<label for=\"contacts\" class=\"contacts\">Contacts</label>";
  echo "<select name=\"contacts\" id=\"contacts\" class=\"contacts\">";
    while($row_contact = mysql_fetch_assoc($query_contact)){
      echo "<option value=\"{$row_contact['ContactID']}\">{$row_contact['first_name']}</option>";
}    
echo "</select>";
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.