admin管理员组文章数量:1336203
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()
本文标签: jqueryI set field value w javascriptonchange not triggered Alternative solutionStack Overflow
版权声明:本文标题:jquery - I set field value w javascript, onchange not triggered. Alternative solution? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742400161a2467723.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论