html - Images In Javascript -


I am creating a small application where multiple images are displayed and when a user clicks on a single image So it gets bigger that changes the image which is in between.
But I can not find the picture clicked.

  & lt; HTML & gt; & Lt; HEAD & gt; & Lt; SCRIPT LANGUAGE = "text / javascript" & gt; Function swapes (this.id) {document.write ("in swapes"); Switch (this.id) {case img2: IMG1.src = "component1 / images / image1.jpg" intImage = 2 return (wrong); Case img3: IMG1.src = "component1 / images / image1.jpg" intImage = 2 return (incorrect); Case img4: IMG1.src = "component 1 / picture / image 1. Jpg" intImage = 2 return (wrong); }} & Lt; / SCRIPT & gt; & Lt; / HEAD> & Lt; Body & gt; & Lt; IMG id = "IMG1" name = "IMG1" src = "image1.jpg" height = "100px" width = "100px" & gt; & Lt; IMG ID = "IMG2" name = "IMG2" height = "40px" width = "40px" src = "image 1.jpg" onclic = "swap image (this.id);" & Gt; & Lt; IMG ID = "IMG3" name = "IMG3" height = "40px" width = "40px" src = "image 2.jpg" onclic = "swap image ();" & Gt; & Lt; A href = "#" & gt; & Lt; IMG ID = "IMG4" name = "IMG4" height = "40px" width = "40px" src = "image 1.jpg" onclic = "swap image ();" & Gt; & Lt; / A & gt; & Lt; / Body & gt; & Lt; / Html & gt;  

How about it?

  & lt; HTML & gt; & Lt; HEAD & gt; & Lt; SCRIPT LANGUAGE = "javascript" & gt; Function swapImage (src) {document.getElementById ("IMG1"). Src = src; } & Lt; / SCRIPT & gt; & Lt; / HEAD> & Lt; Body & gt; & Lt; IMG id = "IMG1" src = "image1.jpg" height = "100px" width = "100px" & gt; & Lt; IMG ID = "IMG2" height = "40px" width = "40px" src = "image 1.jpg" onclic = "swap image (this SRC);" & Gt; & Lt; IMG ID = "IMG3" height = "40px" width = "40px" src = "image 2.jpg" onclic = "swap image (this. Src);" & Gt; & Lt; IMG ID = "IMG4" height = "40px" width = "40px" src = "image 1.jpg" onclic = "swap image (this SRC);" & Gt; & Lt; / Body & gt; & Lt; / Html & gt;  

There are some errors in your code, for example:

  • Documents. The written should not be used like this
  • You are switch / case on non existing variable (img2, img3, img4)
  • Javascript is case sensitive is not equal to IMG 4 IMG 4
  • Returns is a statement if you If you want to return false, you return
  • Each statement should end with a semicolon.
  • The HTML tag names should be written in lowercase
  • In the swapImage function (this must not be at all) this.id is used incorrectly.
  • < Li> ..but this is correct when IMG2 ..
  • .. but IMG3 and IMG4
  • IG tag should not contain "name" in the attribute

Hope it helps.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -