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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T19:29:07+00:00 2026-05-24T19:29:07+00:00

How can I write a script that will change an input field’s text value,

  • 0

How can I write a script that will change an input field’s text value, but the field is not yet created?

The script is loaded before the input field is created. It needs to know that when any input with a certain class is created, it will then have some text put in to its value. Can this be done with live()?

To clarify, the order of events are:

1 – Application-wide JavaScript for the page is loaded. This contains script something along the lines of:

$('.myDiv input').each(function() {
    $(this).val('some text');
});

2 – A second page-specific script is now loaded, which dynamically creates an input on the page, with no value. I CANNOT MODIFY THIS SCRIPT. This is important, I need a solution that does not modify this script (otherwise I wouldn’t be posting here).

$('.myDiv').html('<input type="text" />');
  • 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-24T19:29:08+00:00Added an answer on May 24, 2026 at 7:29 pm

    Yes, live() will do what you want. It will work as long as you use jQuery to add the elements dynamically.

    The jQuery.live() api is clear on this

    Use live() to bind on focus or blur or keyup whenever you want to change the value of the input field.

    $('.clickme').live('click', function() {
      // Live handler called.
    });
    

    UPDATE: assuming you cant change the input elements in any way before the are added.

    $('#container').bind("DOMSubtreeModified",function() { 
       $('input.myClass:not(.alreadyChanged)').val("whatever you want to change it to");
       $('input.myClass:not(.alreadyChanged)').addClass('.alreadyChanged');
    }
    

    This way you don’t need to use live() when a new element is added to the DOM, the function is automatically triggered.

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

Sidebar

Related Questions

I'm looking to write a jQuery function that will change the value of other
I want to write a sh/bash script that can determine whether a particular directory
I've been trying to write a script that will sniff HTTP headers. So far
I want to write script in SQL that will copy these 2 tables(A,B) to
Background I have been asked to write a script that will create a vertical
How can you allow a PHP script to write to a file with high-security
As a simple example, I want to write a CLI script which can print
I'm trying to write a log parsing script to extract failed events. I can
In SQL one can write a query that searches for a name of a
I know that with mysql you can write SQL statements into a .sql file

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.