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

  • SEARCH
  • Home
  • 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 6069597
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:50:22+00:00 2026-05-23T09:50:22+00:00

i am using this code, that works well. Now i need to change only

  • 0

i am using this code, that works well. Now i need to change only the name of inputs, input1, input 2, and so on.

<script type="text/javascript">
    $(document).ready(function() {
        $("#input1 > select.profissao").live('change', function(){ 
            $.ajax({
                type: "POST",
                data: "data=" + $(this).val(),
                url: "drop1.php",
                success: function(html) {
                    $("#input1 > select.estatistica").html(html);
                }
            });
        });
 });
</script>

why reason this version doesn’t work? i already check the code in lint, and none error is detected.
Basically if i copy the code above and change input1 to input2, works well, but my objective is reduce the redundancy.

<script type="text/javascript">
    $(document).ready(function() {
        for (i=1; i<3; i++) {
        $("#input"+i+" > select.profissao").live('change', function(){ 
            $.ajax({
                type: "POST",
                data: "data=" + $(this).val(),
                url: "drop1.php",
                success: function(html) {
                    $("#input"+i+" > select.estatistica").html(html);
                }
            });
        });
        }
    });
</script>

EDIT: the output is something like that <option value=2>Artes</option><option value=1>Humanidades</option> but this is not added to the html

with the loop my drop down simple stops to work

  • 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-23T09:50:23+00:00Added an answer on May 23, 2026 at 9:50 am

    You can try

    <script type="text/javascript">
    $(document).ready(function() {
        for (i=1; i<3; i++) {
            (function(idx){
                $("#input"+idx+" > select.profissao").live('change', function(){ 
                $.ajax({
                    type: "POST",
                    data: "data=" + $(this).val(),
                    url: "drop1.php",
                    success: function(html) {
                    $("#input"+idx+" > select.estatistica").html(html);
                   }
                });
                });
            })(i);
        }
    });
    </script>
    

    And your function get the same reference of i in a scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this basic auto complete JavaScript that works well, but you need to
I am using this code to check that array is present in the HashMap
I have this code that fetches some text from a page using BeautifulSoup soup=
I'm using this code, and I get the stack trace that is listed below.
Ok, I've got this code that I've been using to spit out news to
I have a code that looks like this: using (DC dc = new DC())
I've got some code that looks like this: using (DBDataContext dc = new DBDataContext(ConnectionString))
I've recently been working with code that looks like this: using namespace std; class
I'm makin' a scripting language interpreter using PHP. I have this code in that
This is the code that I'm using to generate a DH keypair: KeyPairGenerator keyGen

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.