javascript - Return a variable to use as image src -


i have variable image needs display based on form field if first form field says xyz123 picture need displayed in server filesystem , named xyz123.jpg

i can't work out syntax put in

<td colspan=3 align="center"><img src="pictures/thumbnails/logo-20170820013631.jpg" alt="logo" border=1 height=150 width=150></img><br>click enlarge.</td> 

this works fine if use static image name, need dynamic

i have function called whenever first field changed

<div><b>edit customer details</b><br><input type="text" name="key" onchange="changedreference(this.name);" placeholder="enter customer id"></div>  //calls function  function changedreference(n) {     var ref = el(n).value;     var img = el(n).value;     if (ref == null || ref == "") return;      var x = getxmlhttprequest();     if (x == null) {         alert("unable xmlhttprequest");         return;     }      var u = "card-get.php?reference=" + encodeuri(ref);      x.open("get", u, false);     x.send();      var t = x.responsetext;     if (t == null || t.indexof('=') < 0) {         alert("unknown customer id [" + ref + "]");         return;     }      var ra = t.split("\n");     var lookup = new object();     (var = 0; < ra.length; i++) {         var pos = ra[i].indexof('=');         if (pos < 0 || pos == 0) continue;          var en = ra[i].substring(0, pos);         var ev = ra[i].substring(pos + 1);          if ((en == "dob" || en == "id1_expiry") && ev.length == 10 && ev.indexof("-") >= 0) {             ev = ev.substring(8, 10) + "/" + ev.substring(5, 7) + "/" + ev.substring(0, 4);         }          var e = el(en);         if (e != null) e.value = ev;     }  } 

so var img holds value need without .jpg need display lost trying make happen.

give image tag in html id

<img id="changingimage" src="pictures/thumbnails/logo-20170820013631.jpg" /> 

now can change image source point filename inside img variable...

document.getelementbyid('changingimage').src="pictures/thumbnails/"+img+".jpg"; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -