javascript - how to select an individual image in <div> tag and and add onclick function to image -


`

<html>  <head>  <body>  <div>    <img src="p1.jpg" alt="a" align="center"  width="200" height="300" onclick="insertpicturetomysql(event);" >    <img src="p2.jpg" alt="b" align="center"  width="200" height="300" onclick="insertpicturetomysql(event);" >     <img src="p3.jpg" alt="c" align="center"  width="200" height="300" onclick="insertpicturetomysql(event);" >  </div>  <br>    <script>  function insertpicturetomysql(evt) {          //event.target dom element of picture          var target = event.target;          //you can e.g. event.target.src path picture...          //here can saving/uploading logic...        <%@ page import="java.sql.*"%>    <%@ page import="java.io.*"%>    <%    connection con=null;    resultset rs=null;    preparedstatement psmt=null;    fileinputstream fis;    string url="jdbc:mysql://192.168.10.13:3306/test";    try{    class.forname("com.mysql.jdbc.driver").newinstance();    con=drivermanager.getconnection(url,"root","root");    file image = window.getselection(image.valueof(image));    psmt=con.preparestatement("insert inimage(name,city,image)"+"values(?,?,?)");    psmt.setstring(1,"barack obama");    psmt.setstring(2,"wasington d.c.");    fis=new fileinputstream(image);    psmt.setbinarystream(3, (inputstream)fis, (int)(image.length()));    int s = psmt.executeupdate();    if(s>0) {    %>    <b><font color="blue">    <% out.println("image uploaded !"); %>    </font></b>    <%    }    else {    out.println("unsucessfull upload image.");    }    con.close();    psmt.close();    }catch(exception ex){    out.println("error in connection : "+ex);    }    %>  }    </body>  </head>  </html>

`i trying same many days can't select individual image in , aim select individual image div tag give function when onclick should store in mysql database.so please me project

<div align="center">   <onclick="return.insertpicturetomysql();" ><img src="images/p1.jpg" alt="a" align="center"  width="200" height="300">   <onclick="return.insertpicturetomysql();"><img src="images/p2.jpg" alt="b" align="center"  width="200" height="300">     </div><br>    <div align="center">   <onclick="return java.insertpicturetomysql();"><img src="images/p1.jpg" alt="a"  align="center" width="200" height="300">   <a target="_blank" href="images/p4.jpg"><img src="images/p2.jpg" alt="b" align="center"  width="200" height="300">   <br>  </div>    <div align="center">   <onclick="return insertpicturetomysql();"><img src="images/p1.jpg" alt="a" align="center" width="200" height="300">   <onclick="return insertpicturetomysql();"><img src="images/p2.jpg" alt="b" align="center" width="200" height="300">   </div><br>  </br>

onclick not html element. attribute of html element. how html code should like:

<div align="center">     <img src="images/p1.jpg" alt="a" align="center"  width="200" height="300" onclick="insertpicturetomysql(event);">     <img src="images/p2.jpg" alt="b" align="center"  width="200" height="300" onclick="insertpicturetomysql(event);"> </div> 

and of course js function:

<script>     function insertpicturetomysql(evt) {         //event.target dom element of picture         var target = event.target;         //you can e.g. event.target.src path picture...         //here can saving/uploading logic...     } </script> 

Comments