Here is the problem I need to figure out using HTML and Java

Here is the problem I need to figure out using HTML and Javascript:

The document must display an image and three buttons. The buttons should be labeled simply 1, 2, and 3. When pressed, each button should change the content of the image to that of a different image.

Thank you

Solution

Program:-

<head>
<title></title>
</head>
<body>
<img src=\"Images/Deva.jpg\" id=\"imgSrc\"/><br /><br />
<!--this keyword can be represent the current id of the click function-->
<input type=\"submit\" name=\"1\" value=\"image1\" id=\"btn1\" onclick=\"myFunc1(this)\"/>
<input type=\"submit\" name=\"2\" value=\"image2\" id=\"btn2\" onclick=\"myFunc1(this)\"/>
<input type=\"submit\" name=\"3\" value=\"image3\" id=\"btn3\" onclick=\"myFunc1(this)\"/>

<script>
function myFunc1(id)
{
//id represent the id of the click button
//you have to change the src valu dynamically
//images name and button value name is same other wise it not working.
document.getElementById(\'imgSrc\').src = \"Images/\" + id.value + \".jpg\"
}
</script>
</body>
</html>

Here is the problem I need to figure out using HTML and Javascript: The document must display an image and three buttons. The buttons should be labeled simply 1

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site