Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6225527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:51:31+00:00 2026-05-24T08:51:31+00:00

I have this code: <script language=javascript> $(function() { $(‘#items,#button-search’).hide(); $(#companies).click(function() { $(this).attr(value,); $(‘#address,#new-company-form’).empty(); });

  • 0

I have this code:

    <script  language="javascript">
  $(function() {
    $('#items,#button-search').hide();
    $("#companies").click(function() { 
      $(this).attr("value",""); 
      $('#address,#new-company-form').empty();
    });
    $( "#companies" ).autocomplete({
      source: ";companies",
      minLength: 2,
      select: function( event, ui ) {
        $('#address').show();
        if(ui.item.id == "create-new-company") {
          // call the new company form
          $('#address').empty();
          //$('#new-company-form').load('/companies/;new_resource?type=company #autoform',
          $('#new-company-form').load(';company_form #autoform');
        } // end 'if'
        else
        {
          $('#new-company-form').empty();
          $.ajax({
            type: 'GET',
            url: ';addresses?company=' + ui.item.id,
            dataType: 'json',
              // process the addresses
              success: function(json) {
                var opts = '';
                $.each(json, function(k, v) {
                  opts += '<option value="'+k+'">' + v + '</option>';
                });
                $('#address').html('<select>' + opts + '</select>');
                // we click on a select value .change(function () {
                $("#address").change(function () {
                  var id = $(":selected", this).val();
                  if(id == "create-new-address") {
                    $('#new-address-form').load(';address_form #autoform');
                  }
                  else
                  {
                    alert('Request completed' + id);
                  //  pass the id value to the application
                  }
                }) // end click event
              }
            }); //end ajax call to address

        } // end else
            } // end select address
        }); // end autocomplete
    }); // end function
</script>

everytime i run the form, the ‘alert(‘Request completed’ + id);’ on line 41 displays 4 times when i click on an option value.

Is there any way to improve this?

Thanks

Norman

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:51:32+00:00Added an answer on May 24, 2026 at 8:51 am

    You are setting jQuery event handlers inside your autoComplete select function. So, everytime the select function for autocomplete is called, you do this:

    $("#address").change(function() {
    

    That means that this event handler is getting added over and over again (thus it gets called multiple times). You need to add that event handler once outside the autocomplete framework, not inside the autocomplete function or the select handler.

    I think you want it to be like this:

    <script language="javascript">
    $(function() {
        $('#items,#button-search').hide();
        $("#companies").click(function() {
            $(this).attr("value", "");
            $('#address,#new-company-form').empty();
        });
        // we click on a select value .change(function () {
        $("#address").change(function() {
            var id = $(":selected", this).val();
            if (id == "create-new-address") {
                $('#new-address-form').load(';address_form #autoform');
            } else {
                alert('Request completed' + id);
                //  pass the id value to the application
            }
        }) // end click event
        $("#companies").autocomplete({
            source: ";companies",
            minLength: 2,
            select: function(event, ui) {
                $('#address').show();
                if (ui.item.id == "create-new-company") {
                    // call the new company form
                    $('#address').empty();
                    //$('#new-company-form').load('/companies/;new_resource?type=company #autoform',
                    $('#new-company-form').load(';company_form #autoform');
                } // end 'if'
                else {
                    $('#new-company-form').empty();
                    $.ajax({
                        type: 'GET',
                        url: ';addresses?company=' + ui.item.id,
                        dataType: 'json',
                        // process the addresses
                        success: function(json) {
                            var opts = '';
                            $.each(json, function(k, v) {
                                opts += '<option value="' + k + '">' + v + '</option>';
                            });
                            $('#address').html('<select>' + opts + '</select>');
                        }
                    }); //end ajax call to address
                } // end else
            } // end select address
        }); // end autocomplete
    }); // end function
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this simple code that speaks for itself. <script language='javascript"> function check() {}
Okay, I have this code: <script language=javascript type=text/javascript> <!-- function requestPage(page) { var request
I have this code in the HEAD: <script LANGUAGE=JavaScript> <!-- function calculate(form) { height
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
I have a JavaScript function, in this function i will write <script type='text/JavaScript' language='JavaScript'>alert('ha')</script>
This is the javascript code im using. <script language=javascript type=text/javascript> function cancelevent() { input_box=confirm(Are
i have this js piece of code: <script language=JavaScript type=text/javascript> var sendReq = getXmlHttpRequestObject();
I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
I have this html code <html> <head> <title>JQuery Problem 2</title> <script type=text/javascript src=jquery-1.4.min.js></script> <script
I have an application that contains this code: <script src=Scripts/jquery-1.4.1.min.js type=text/javascript></script> <script src=Scripts/facebox.js type=text/javascript></script>

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.