0

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.

1
  • 1. are you using jquery or pure javascript and 2. please post some more of the html of what you are trying to do. Thanks. Commented Dec 20, 2010 at 6:46

2 Answers 2

1

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 try document.getElementById('addProductLinksCreateForm:addProductLinkUrlValue').onchange = onImgChange; to allow that to happen when the user switches to a different text box.

Sign up to request clarification or add additional context in comments.

Comments

0

Using jQuery, it would look like:

function onImgChange() {
     $('#yui_img').attr('src', function(i, src) {
         return $('#addProductLinksCreateForm').attr('src');
     });
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.