when i select the image image name should display using jquery

nishan kishan

when i click the image and click add button image name should shown on alert message.but it is now working. what i tried the code so far i attached below if i click Chocolate image alert msg displayed Chocolate same like i need to do.

this is the form

 <div class="form-group">

      <div >
           <img class="photo" id="Chocolate" src="images/chocolate-ice.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal"    >

    <b>Chocolate</b>
     </div>

   <div>
     <img src="images/mango.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

  <b>Mango</b>
     </div>

       <div  >

         <img class="photo" id="Venila" src="images/venila.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

          <b>Venila</b>
             </div>

               <div >

                <img class="photo" id="Strawberry" src="images/sww.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

                  <b>Strawberry</b>
                  </div>

                  <div>

                 <img class="photo" id="MixFruit" src="images/mixfruit.jpg" width="100" height="100" >

            <b>MixFruit</b>


              </div>
  <input type="button" class="btn btn-info" value="ADD" onclick="add()">

               </div>
               </form>

if i click Chocolate image alert msg displayed Chocolate same like i need to do jQuery

function add()
{


if("Chocolate")

    {
    alert("Chocolate");

    }
else if("Venila")

{

    alert("Venila");
}
else if("Strawberry")

{
  alert("Strawberry");

}
else if("Mixfruit")

{
    alert("Mixfruit");
}
Swati

Try like below :

var a="";
//on click of image get id value
$("img").on("click",function(){
   a=$(this).prop('id')

});

function add() {


if(a==="Chocolate")

  {
    alert("Chocolate");

  } else if(a==="Venila")

  {

    alert("Venila");
  } else if(a==="Strawberry")

  {
    alert("Strawberry");

  } else if(a==="MixFruit")

  {
    alert("Mixfruit");
  } else{
    alert("Mango");
  }
  }
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<div class="form-group">

  <div>
    <img class="photo" id="Chocolate" src="images/chocolate-ice.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

    <b>Chocolate</b>
  </div>

  <div>
    <img src="images/mango.jpg" id="Mango" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

    <b>Mango</b>
  </div>

  <div>

    <img class="photo" id="Venila" src="images/venila.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

    <b>Venila</b>
  </div>

  <div>

    <img class="photo" id="Strawberry" src="images/sww.jpg" width="100" height="100" data-toggle="modal" data-target="#exampleModal">

    <b>Strawberry</b>
  </div>

  <div>

    <img class="photo" id="MixFruit" src="images/mixfruit.jpg" width="100" height="100">

    <b>MixFruit</b>


  </div>
  <input type="button" class="btn btn-info" value="ADD" onclick="add()">

</div>
</form>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How should I expand a div using jquery when clicked on image?

Display / hide button when I select image

When I left click the image the menu should display in wpf

how to show tick mark and an overlay on image while clicking an image, but when i click other image it should hide and display the same on new image?

display image on another window when click select button using Javascript

Display image using Jquery "find"

display the name of the image using onchange="readURL(this);"

Select and display image(s) using FileReader

how do i display image with a specific file name using part of the file name

why image display below when click on image in Jquery?

Display an image from JSON using jQuery

Display text and image using jquery qtip

Preview the image with display height and width using jQuery

How to display image object using Javascript / Jquery

display image in jquery dialog using html body

display multiple image into HTML table using jquery

How do I display image count of specific type of image with jQuery?

jQuery change image when SELECT changes

How to display image from database instead of image path using jQuery

ImageButton wont display image when using srcCompat

When uploading an image, I want to display just that image

get the name of image when i upload it

How can I display an image using Pillow?

I cannot display an image using shiny app?

How to save image link in when using 'require' to display image in VueJS?

How to select Image using jquery and upload it?

React Native How to get the image name when using image picker?

What Should I Do If a HUAWEI Quick App Freezes When the canvas Component Draws an Image Using setInterval?

how do I select xpath image without a class name using selenium in python?