Sponsored Content
Top Forums Programming Javascript: displaying images with onchange event Post 302925505 by figaro on Monday 17th of November 2014 02:18:51 PM
Old 11-17-2014
Javascript: displaying images with onchange event

I am looking to display the pdf of one of two distributions, depending on what the user selected:

Code:
<script type="text/javascript">
function distributionChange() {
  var img = document.createElement("img");
  var link = 'http://en.wikipedia.org/wiki/xxx#mediaviewer/File:yyy';

  switch (document.getElementById("distributions").value) {
    case 'normal':
      img.src = link.replace("xxx", "Normal_distribution").replace("yyy", "Normal_Distribution_PDF.svg");
      break;
    case 'lognormal':
      img.src = link.replace("xxx", "Log-normal_distribution").replace("yyy", "Some_log-normal_distributions.svg");
      break;
    default:
      img.src = "Distribution not specified.";
  }

  img.setAttribute("width", "320");
  document.getElementById("distribution").appendChild(img);
}
</script>

<select id='distributions' onChange='distributionChange()'>
<option name='option0' value='normal'>normal</option>
<option name='option1' value='lognormal'>lognormal</option>
</select>

<div id="distribution"></div>

Two questions on this:
1- Why are the images appended and not recreated? Rather than overwriting the previous image, the new image is shown next to the old one.
2- Why is the image not actually shown? When doing Ctrl-Shift-J in my browser, the link to the image is correct.
 

3 More Discussions You Might Find Interesting

1. AIX

where to get .bm or .pm images

I'm just trying to get a personal picture for a backdrop on my AIX user account at work. Where does one acquire the .bm or .pm files. How do I create them as an unpriveledged user? There are quite a few jpeg's that I would like to use. (0 Replies)
Discussion started by: trigggl
0 Replies

2. UNIX for Dummies Questions & Answers

onChange + javascript in perl CGI - question

Hello all, Am trying to include a onChange java script to my perl CGI application which uses POST method to upload files to file_server This is how I embedded javascript in the perl code that renders CGI application print qq| <script type="text/javascript" src="display.js"> </script>... (4 Replies)
Discussion started by: matrixmadhan
4 Replies

3. Shell Programming and Scripting

Bash Script to find/sort/move images/duplicate images from USB drive

Ultimately, I'm looking to create a script that allows me to plug in a usb drive with lots of jpegs on it & copy them over to a folder on my hard drive. So in the process of copying I am looking to hash check them, record dupes to a file, copy only 1 of the identical files (if it doesn't exsist... (1 Reply)
Discussion started by: JonaQuinn
1 Replies
img-intro(n)															      img-intro(n)

__________________________________________________________________________________________________________________________________________________

NAME
img-intro - Introduction to Img SYNOPSIS
package require Tk package require Img ?1.4? _________________________________________________________________ DESCRIPTION
Img is a Tk extension, adding support for many other Image formats, as listed below. The individual formats are described in more detail on their own pages. bmp Windows bitmap format. See img-bmp. dted DTED terrain elevation data interpreted as image. See img-dted. gif The venerable graphics interchange format (with transparency, but without LZW. The latter due to patent issues). See img-gif. ico Windows icon files. See img-ico. jpeg The format for lossy compressed still pictures specified by the Joint Picture Experts Group. See img-jpeg. pcx Paintbrush image format. See img-pcx. pixmap While the other formats are handlers for the Tk photo image type this is a new image type for Tk. See img-pixmap. png Portable Network Graphics, successor to GIF. See img-png. ppm Portable Pixmaps. See img-ppm. ps Postscript and PDF (Portable document format). Requires an external application, ghostview, for its operation. See img-ps. raw Raw matrix data interpreted as image. See img-raw. sgi Native SGI format. See img-sgi. sun Sun raster images. See img-sun. tga Targa files. See img-tga. tiff Tagged Interchange File Format. See img-tiff. window Put the content of a Tk window into an image. See img-window. xbm X Bitmaps. See img-xbm. xpm X Pixmaps. See img-xpm. This version only works with Tcl/Tk 8.3 or higher. If you are using Tk 8.2, please use Img 1.3. If you are using Tk 8.1 or lower please stick with Img 1.2.4 (which is still available). And if you are using Tk4.2 or lower, please stick with Img 1.1.4 (which is also still available). SEE ALSO
img-bmp, img-dted, img-gif, img-ico, img-jpeg, img-pcx, img-pixmap, img-png, img-ppm, img-ps, img-raw, img-sgi, img-sun, img-tga, img-tiff, img-window, img-xbm, img-xpm KEYWORDS
bmp, gif, ico, image handling, jpeg, pcx, pdf, pixmap, png, postscript, ppm, ps, sgi, sun, tga, tiff, tk, window, xbm, xpm COPYRIGHT
Copyright (c) 1995-2009 Jan Nijtmans <nijtmans@users.sourceforge.net> Img 1.4 img-intro(n)
All times are GMT -4. The time now is 07:02 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy