I need to change the html img src value dynamically from the value from hidden text field using Jquery or Java script.
<p><开发者_运维知识库;img id="yui_img" height="333" width="345"></p>
function onImgChange()
{
document.getElementById('yui_img').src=document.getElementById('addProductLinksCreateForm:addProductLinkUrlValue').value;
}
I got the value in the DOM but it is not getting reflected in it. Old image is maintained.
This should work, but you need to ensure that these are the case:
Does the textbox tag look like
<input type="text" id="addProductLinksCreateForm:addProductLinkUrlValue">
?Are you calling
onImgChange()
at all? You could trydocument.getElementById('addProductLinksCreateForm:addProductLinkUrlValue').onchange = onImgChange;
to allow that to happen when the user switches to a different text box.
Using jQuery, it would look like:
function onImgChange() {
$('#yui_img').attr('src', function(i, src) {
return $('#addProductLinksCreateForm').attr('src');
});
}
精彩评论