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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:51:38+00:00 2026-05-29T07:51:38+00:00

I have 2 functions: the first one will update an input field, and the

  • 0

I have 2 functions: the first one will update an input field, and the second one will show an image if the input value is a valid image.

I can not merge them into only one function because they are working on separated pages (I have just putted them on one page for the example). Also I can not change the first function!

Instead of .change if I use .blur or .focusout I have to click in and out the input box to update the image. How can I get it working without extra clicks?

<script type="text/javascript">
$(document).ready(function() {
   $("input:radio").click(function() {
      $("#image").val($(this).val());
   });
});



$(document).ready(function() {
   $('#image').change(function() {
      var src = $(this).val();
      $('#imagePreview').html(src ? '<img src="' + src + '">' : '');
   });
});
</script>

<form>
<input type="radio" name="name" value="http://www.w3schools.com/images/w3schoolslogo.gif" /> IMG<br />
<input type="radio" name="name" value="http://www.google.bg/logos/classicplus.png" /> IMG<br />
<input type="radio" name="name" value="http://www.w3schools.com/images/w3schoolslogo.gif" /> IMG<br />
<input type="radio" name="name" value="http://www.google.bg/logos/classicplus.png" /> IMG<br />
<input type="radio" name="name" value="http://www.w3schools.com/images/w3schoolslogo.gif" /> IMG<br />
</form>


<input id="image" type="text" name="fname" />



<div id="imagePreview">

</div>
  • 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-29T07:51:39+00:00Added an answer on May 29, 2026 at 7:51 am

    The change event requires the following three things happen:

    1. Element gain focus
    2. Value change
    3. Focus blur from element

    If you are changing the value of an input programmatically, then you must manually trigger the change event via jQuery’s .trigger('change') or the .change() shortcut.

    Ideally, you would modify the first function to trigger change:

    $(document).ready(function () {
       $("input:radio").bind('click', function () {
          $("#image")
            .val($(this).val())
            .trigger('change');
       });
    });
    
    
    
    $(document).ready(function () {
       $('#image').bind('change', function () {
          var src = $(this).val();
          $('#imagePreview').html(src ? '<img src="' + src + '">' : '');
       });
    });
    

    However, per your question text, you cannot change the first function as I have suggested. This being the case, there is no good option for you, IMO. You could set up a timing interval to poll the input for its value and trigger the change event if you notice that it is different from the last check, but that’s just ugly. Regardless, you need to cause the change event to fire.

    Ugly:

    //LEAVE FIRST FUNCTION ALONE
    
    $(document).ready(function () {
      var $imageInput = $("#image"),
        $imagePreview = $('#imagePreview'),
        lastVal;
    
      $imageInput.bind('change', function () {
        var src = $(this).val();
        $imagePreview.html(src ? '<img src="' + src + '">' : '');
      });
    
      lastVal = $imageInput.val();
    
      setInterval(function () {
        var currentVal = $imageInput.val();
    
        if (currentVal !== lastVal) {
          $imageInput.trigger('change');
          lastVal = currentVal;
        }
      }, 500);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple url that will toggle one field in my search model.
I have a simple question related to one-line programming. First an example: function test(a)
Assuming I have the following two JQuery functions - The first, which works: $(#myLink_931).click(function
I have the following dead simple elisp functions; the first removes the fill breaks
I have a function which first reads an image from disk, resizes it and
I have a two forms on a page. The first one has several quantity
I have two functions, one that makes an Ajax request when the user loads
I have this code: <input type=checkbox id=checkbox value=11> <input type=checkbox id=checkbox value=10> <div id=log></div>
At the core of one of our applications we have to merge key value
We have a function that pulls the date from the first 8 characters of

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.