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 873291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:54:32+00:00 2026-05-15T10:54:32+00:00

i have successfully added input element into div, which looks like this : $(document).ready(function()

  • 0

i have successfully added input element into div, which looks like this :

$(document).ready(function() {
  $('#jumlah').change(function() {
 var jum = $('#jumlah').val();

 for(i=1;i<=jum; i++){
     $('#jawaban').append('<label>Jawaban Soal ' + i + ' : </label><input type="text" name="jawab'+i+'" id="jawab[]" size="2" maxlength="1" /><br>');
 }
  });
});

and some my HTML codes are :

<select name="jumlah" id="jumlah" class="test">
    <option value="0" selected="selected">choose value</option>
    <?php
  for($i=1;$i<=20;$i++)
   echo("<option value=\"$i\">$i</option>");
 ?>
</select>

<div id="jawaban"></div>

but when i choose different value, it appends more input elements under the first ones, for example, if i choose option 2 and then option 3 it will look like :

Jawaban Soal 1 : <input />
Jawaban Soal 2 : <input />
Jawaban Soal 1 : <input />
Jawaban Soal 2 : <input />
Jawaban Soal 3 : <input />

Please help, i’m still junior in Jquery. I’m looking forward to your respond.

  • 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-15T10:54:33+00:00Added an answer on May 15, 2026 at 10:54 am

    I’m guessing you want the old ones to disappear, in which case you should empty the jawaban div first.

    $(document).ready(function() {
      $('#jumlah').change(function() {
         var jum = $('#jumlah').val();
    
         $('#jawaban').empty();
    
         for(i=1;i<=jum; i++){
             $('#jawaban').append('<label>Jawaban Soal ' + i + ' : </label><input type="text" name="jawab'+i+'" id="jawab[]" size="2" maxlength="1" /><br>');
         }
      });
    });
    

    You (infact a considerable amount of people), should cache the jQuery objects you build. Each time you use $('someSelector') in your code, jQuery re-selects your elements, and returns a new object for you each time. this is none trivial!

    $(document).ready(function() {
      $('#jumlah').change(function() {
         var jum = +$('#jumlah').val(); // convert this to an integer (it's a string otherwise)
         var jawaban = $('#jawaban').empty();
    
         for(var i=1;i<=jum; i++){ // don't forget to initialize i!
             jawaban.append('<label>Jawaban Soal ' + i + ' : </label><input type="text" name="jawab'+i+'" id="jawab[]" size="2" maxlength="1" /><br />');
         }
      });
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am building an Android app using phoneGap and I have successfully added the
I have a png icon, it's added successfully in my project, but not included
I have a page in which I have a div. The content from that
I have a form which contains list of data, I added a checkbox in
I am learning maps in iphopne i have read a tutorial and successfully added
I have a model class like this: namespace Models { public struct Localization {
This is an extension to my previous question . I've successfully added a button
I have this simeple jQuery code: $('#category_name').change(function() { alert('Handler for .change() called.'); var category
This isn't a real fluent interface. I have an object which builds up a
I'm sure i've badly written this. I have a simple form which you enters

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.