write a function on java script using onmouseover event to change the picture . "When the user moves the mouse pointer over the green image, A function should be called to change the source of image to “greenpanadol.jpg” and to set the price variable to 1.500 BHD. The price value and BHD sign should be placed inside "

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

write a function on java script using onmouseover event to change the picture .

"When the user moves the mouse pointer over the green image, A function should be called to change the source of image to “greenpanadol.jpg” and to set the price variable to 1.500 BHD. The price value and BHD sign should be placed inside <p id="price"> </p>"

Expert Solution
Program Instruction
  • In style tag:
    • img2 is for target image, that is, greenpanadol.
    • img1, is for red color
    • img3 is for green color, and
    • price is for paragraph.
  • In body tag three images are created with the above mentioned tags.
  • A paragraph with id as price is also created. Its display style is hidden.
  • On hovering over img3, the border changes and img2 is displayed along with price.
  • On hovering out of img3, the border changes back to normal and img2 and price is not displayed anymore.
Program

<!DOCTYPE HTML>
<html>
  <head>
    <meta charset="utf-8">
    <title>Image hover demo</title>
    <style>
      #img2
      {
        position: top;
        margin-right:auto;
        display: none;
      }

      #img1:hover
      {
        border-width: "1px";
        border-color: white;
        border-style: solid;
      }

      #img3:hover
      {
        border-width: "1px";
        border-color: black;
        border-style: solid;
      }

      #price
      {
        display: none;
      }
    </style>
  </head>

  <body>
    <img id="img2" src="greenpanadol.png"
    width = "300" height = "300"/>
    <b>Color: </b>
    <img id="img1" src="https://i.ytimg.com/vi/fOoeCpN6mmY/maxresdefault.jpg"
    width = "30" height = "30"/>
    <img id="img3"
    src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAYwAAAB/CAMAAADLlgV7AAAAA1BMVEUAzADANaWYAAAASElEQVR4nO3BMQEAAADCoPVPbQsvoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAICjAcTzAAEggOyyAAAAAElFTkSuQmCC"
    width="30" height="30"/>
    <b><p id="price">Price: 1.500 BHD</p></b>

    <form>
      <b><label for="cars">Quantity:</label></b>
      <select name="quant" id="qty">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
      <option value="4">4</option>
      <pre><input type="submit" value="+Add">
    </select>
    </form>

    <script>
      var img1 = document.getElementById("img1"),
          img2 = document.getElementById("img2");
          img3 = document.getElementById("img3");
          Price = document.getElementById("price");

      img3.onmouseover = function(){
        img2.style.display = "block";
        price.style.display = "block";
      }

      img3.onmouseout = function(){
        img2.style.display = "none";
        price.style.display = "none";
      }
    </script>
  </body>
</html>

steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Knowledge Booster
JQuery and Javascript
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education