I have read some solutions to this, none of which are hassle free, so I thought maybe some modern solution now exist to remedy this. It should anyways, since the problem has been around for a while. Something in the more recent jQuery updates perhaaps?
I set my form field like this:
parent.window.document.getElementById(parent.window.imageInputField).value = '{{ path }}'+image;
and I have an onchange event like this that I would like to fire upon my field update as of above.
$('#data_1').change(function(){
img = "url(" + $('#data_1').val() + ")"
$('#slide_bg').css("backgroundImage", img );
});
UPDATE
so this code works fine:
alert( $('#'+parent.window.imageInputField, window.parent.document).val() );
while this doesn't do anything, no error or nothing
$('#'+parent.window.imageInputField, window.parent.document).change();
The change event is defined here
$('#data_1').change(function(){
alert('change event called');
img = "url(" + $('#data_1').val() + ")"
$('#slide_bg').css("backgroundImage", img );
});
and this works perfect:
<input type='button' value='Uppdatera förhandsgr.' onclick="$('#data_1').change()" />
All I want is to trigger what this button does, but by code... anyone see where I went wrong?
I have read some solutions to this, none of which are hassle free, so I thought maybe some modern solution now exist to remedy this. It should anyways, since the problem has been around for a while. Something in the more recent jQuery updates perhaaps?
I set my form field like this:
parent.window.document.getElementById(parent.window.imageInputField).value = '{{ path }}'+image;
and I have an onchange event like this that I would like to fire upon my field update as of above.
$('#data_1').change(function(){
img = "url(" + $('#data_1').val() + ")"
$('#slide_bg').css("backgroundImage", img );
});
UPDATE
so this code works fine:
alert( $('#'+parent.window.imageInputField, window.parent.document).val() );
while this doesn't do anything, no error or nothing
$('#'+parent.window.imageInputField, window.parent.document).change();
The change event is defined here
$('#data_1').change(function(){
alert('change event called');
img = "url(" + $('#data_1').val() + ")"
$('#slide_bg').css("backgroundImage", img );
});
and this works perfect:
<input type='button' value='Uppdatera förhandsgr.' onclick="$('#data_1').change()" />
All I want is to trigger what this button does, but by code... anyone see where I went wrong?
Share Improve this question edited Dec 31, 2012 at 18:31 Matt Welander asked Dec 29, 2012 at 19:39 Matt WelanderMatt Welander 8,55825 gold badges96 silver badges146 bronze badges 2- I don't understand, you are looking for an onChangeProperty event? – HMarioD Commented Dec 29, 2012 at 19:43
- Yes, that fires when I javascript-programattically change the contents of an input field (the onchange event only fires when the user puts the cursor in the field, updates the contents and blurs from the field. – Matt Welander Commented Dec 29, 2012 at 20:36
1 Answer
Reset to default 6you need to trigger the change handler with your code. Updating a value with script will not trigger change
event
parent.window.document.getElementById(parent.window.imageInputField).value = '{{ path }}'+image;
$('#data_1').change()
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742400164a4436749.html
评论列表(0条)