How to concatenate <img src=" string" +document.getElementById(' ').value

Viewed 1099

I'm trying to display images using <img src="" with the image path, but adding the actual image.png file as a variable from a text field. I keep getting an error that the file does not exist... but it does.

I have tried searching the web, but nothing has fit this particular problem.

<label class="buslabel" for="Name">Window Pane Image:
   <strong><input id="WindowPaneImage" style="margin-left: 10px; border: 
      none; padding: 0;" type="text" class="busaddinput" 
      placeholder="Image.png" name="WindowPane" size="15" maxlength="15"        
      ></strong>
 </label>


<img src="C:/Users/jaydr_000/Desktop/Web Development/SFF/Vend-images/ + 
   document.getElementById('WindowPaneImage').value" 
   class="FrameRectangle">

Need to be able to get the input field [image name] and pass it to the

I keep getting an error that the file does not exist..., it does exist.

1 Answers

This seems to do the work : As soon as you enter the name of the picture and click anywhere, the new image is served.

<body onclick="foo()">
<label class="buslabel" for="Name">Window Pane Image:

<strong><input id="WindowPaneImage" style="margin-left: 10px; border: none; padding: 0;" type="text" class="busaddinput" placeholder="Image.png" name="WindowPane" size="15" maxlength="15" 
value= ""></strong>

 </label>


 <img src= "" class="FrameRectangle" id="img">


 <script>  
    function foo(){  
    var name1=document.getElementById("WindowPaneImage").value;  
    document.getElementById("img").src = name1; 
    }  
 </script>  
 </body>
Related