0

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! :)

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Macko888
0

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.

0

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>";
?>
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.