javascript - JS: more efficient way to call an image -


Hi, I am trying to output an image and my previous method is like this:

Code:

  

Every time the user changes his option, the image also changes, I feel okay, but at present I am trying to do something like that,

< P> Expanded:

Input (label / text): ImageA.jpg Button: Click me

desired output: image pop out

desired process: < / P>

Do not choose any more options & lt; Select name = "" & gt; & Lt; Opt ... & lt; / Select & gt; , when the button is clicked, it is "Img2 /" + selected + ".jpg"; Which is locally

or & lt; Select name = "" & gt; & Lt; Opt-In ... & lt; / Select & gt; can not be deleted, change to something else, because it indicates an error in the console in the current setup, so I am searching for a more efficient way

thnx help all Is appreciated

Update

  function addTheImage () {var img = document.createElement ('img '); Img.src = "http: // ...."; Document.body.appendChild (img); }  

  & lt; Html & gt; & Lt; Top & gt; & Lt; Script type = "text / javascript" & gt; Function addimage () {selected = document.getElementById ("Country"). Values; Var src = "img2" "+ selected +" .jpg "; var img = document.createElement (" img "); Img.src = src; container.appendChild (img); Img.style.display =" inline "; } & Lt; / script> & lt; body & gt; input class = "buildaddress" id = "country" & gt; & gt; input type = "button" onclick = "addimage ()" value = "Display" & gt; div id = "container" & gt; & lt; / div & gt; & lt; / body & gt;  

People with my answers It is posting to others who have the same problem at night, also ask for their opinion how to limit it to an append child, its unlimited reasons


Comments