homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

jQwery on onchange

5+ Year Member

Msg#: 4414706 posted 3:42 pm on Feb 6, 2012 (gmt 0)

I have a `input` text field which is filled with the url of an image using a jQuery function.

After changing the url, I need the new image displayed. But when I use the `.change` jQuery event, the image only gets updated if the field is changed by the keyboard.

I have the function that updates the image but how do I trigger it even when the field is changed via another function rather than the keyboard?

How do I use the "onChange" event of the `input` to run the jQuery function?

This is the function which sets the value of the input box with a url

function selectURL(url) {
if (url == '') return false;
field = window.top.opener.browserWin.document.forms[0].elements[window.top.opener.browserField];
field.value = url;
if (field.onchange != null) field.onchange();

The function which updates the image:

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

Probably if using the `onchange` element of the input box for executing the jQuery function will be working properly and I was asking for this!



WebmasterWorld Senior Member 5+ Year Member

Msg#: 4414706 posted 6:29 am on Feb 7, 2012 (gmt 0)

Try changing
if (field.onchange != null) field.onchange();

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved