Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

jQwery on onchange

3:42 pm on Feb 6, 2012 (gmt 0)

New User

5+ Year Member

joined:July 30, 2009
posts: 7
votes: 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!
6:29 am on Feb 7, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Nov 3, 2005
votes: 0

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

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members