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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:19:45+00:00 2026-05-27T13:19:45+00:00

I have this input that has text and when you click it, the text

  • 0

I have this input that has text and when you click it, the text dissapears but if you didnt type anything the text will come back.

<input type="button" id="btnAdd" value="Add Answer" />
<input type="text" id="forminput" class="clonedInput" onclick="this.value='';" 
onfocus="this.select()"onblur="this.value=!this.value?'Answer 1
':this.value;" value="Answer 1" />

I have a button that clones and increments my current input field using this function.

This is the function incrementing my current input field but i also need to increment the Answer #.

$('#btnAdd').click(function() {
var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
var newNum = new Number(num + 1); // the numeric ID of the new input field being added

// create the new element via clone(), and manipulate it's ID using newNum value
var newElem = $('#formanswer' + num).clone().attr('id', 'formanswer' + newNum);

// manipulate the name/id values of the input inside the new element
newElem.children(':first').attr('id', 'formanswer' + newNum).attr('value','Answer '+newNum);

 // insert the new element after the last "duplicatable" input field
 $('#formanswer' + num).after(newElem);

My problem is that i need to increment the text inside the new input field to make it dynamically incrementing by one each time it is cloned. Ive been baning the wall against my head for hours but i hope it isnt some easy php var. plz help me :~)

  • 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-27T13:19:46+00:00Added an answer on May 27, 2026 at 1:19 pm

    Here’s a fiddle which is working, and I think does what you’re attempting:

    http://jsfiddle.net/R2tFz/

    For posterity, here is the javascript I created:

    $(function () {
    
    $('#btnAdd').click(function() {
    var num = $('.clonedInput').length; // how many "duplicatable" input fields we currently have
    //clone the last field    
    
    var newNum = num + 1; // the numeric ID of the new input field being added
    
        var newElem = $('#formanswer' + num).clone().attr('id', 'formanswer' + newNum);
    
    // create the new element via clone(), and manipulate it's ID using newNum value
    
    // manipulate the name/id values of the input inside the new element
    $("input", newElem).attr('name', 'formanswer' + newNum).val('Answer ' + newNum);
    
     // insert the new element after the last "duplicatable" input field
     newElem.insertAfter($('#formanswer' + num));
    
    });
    
    
        $(".clonedInput").live('blur', function () {
         var num = $(this).attr('name').replace('formanswer', '');
         $(this).val( (!$(this).val().length)?('Answer '+num):$(this).val() );
        }); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this input text: <html><head><meta http-equiv=content-type content=text/html; charset=utf-8></head><body><table cellspacing=0 cellpadding=0 border=0 align=center width=603>
I have this input in a form: <input type=text value=<script src='/js/script.js' type='text/javascript'></script> name=embed/> The
We have a layer that appears when a certain text input has the focus
I have a form that has 3 text boxes for 3 input values, along
I have the following html code: <input type=text id=theInput value=/> <a href=# id=theLink>Click me</a>
Ok say you have this: <input id=test value= /> Value of that input is
I have a model that is something like this: class Input(models.Model): details = models.CharField(max_length=1000)
I have to write a Matlab script that does this: The input is 2
I hope I can explain this right I have two input fields that require
I have an if statement that needs to look like this: UPDATE $(input#textbox).keypress(function(e){ key==e.which;

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.