Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi i have two image(correct or error ) in my table , i want to show alert only on correct image ?

i used this code..
var td4 = document.createElement('td');
C#
var img = document.createElement('img');
        img.setAttribute('width', '24');
        img.setAttribute('height', '24');
        td4.setAttribute('style','width:3%');
        td4.setAttribute('align','center');
        (function(id) {
       img.onclick = function(e) {
      e.preventDefault();
      e.stopPropagation();
      // now it will alert the id (what is the i of the for-loop):
      if( img.attr('src')== "images/correct-icon.png")
      alert(id);
      };
     }(i));

XML
if(serviceAlertPresent[i].firstChild.nodeValue == 'false'||otherAlertPresent[i].firstChild.nodeValue == 'false')
{
     img.src='images/correct-icon.png';
    //td4.innerHTML = "<img src=\"images/correct-icon.png\" width=\"20\" height=\"20\" />";
    td5.innerHTML="";
}
else
{
    img.src='images/error-msg.png';
    //td4.innerHTML = "<img src=\"images/error-msg.png\" width=\"20\" height=\"20\" />";
    td5.innerHTML=expDepart[i].firstChild.nodeValue ;
}
    td4.appendChild(img);


alert Id is not display...?
How to display id..
Posted

1 solution

hi check out the following
link1[^]
link2[^]
 
Share this answer
 
Comments
ravi1989h 18-Oct-12 3:29am    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>First Group</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<link href="style/scrollbar.css" rel="stylesheet" type="text/css" />
<link href="style/autosuggest.css" rel="stylesheet" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<script type="text/javascript" src="script/jquery.min.js"></script>
<script type="text/javascript" src="script/iScroll.js"></script>
<script type="text/javascript" src="cordova-1.9.0.js"></script>
<script type="text/javascript" src="script/common.js"></script>
<script type="text/javascript" src="script/soapclient.js"></script>
<script type="text/javascript" src="script/soapclientfilter.js"></script>
<script type="text/javascript" src="script/autosuggest.js"></script>
<script type="text/javascript">
var isfilterRequired=false;
var myTimedCall;
function lastStationData(){

var r = window.localStorage.getItem("lastDepartureStation")||[];
var params = getParams();
var parameter1 = unescape(params["menu"]);
if(parameter1=="false"){
if(r!=null){

var stationName = window.localStorage.getItem("lastDepartureStation");
document.getElementById("getStationDesc").value=stationName;
callWebservice(stationName.substring(0,3));
}

}else{
var stationName = window.localStorage.getItem("lastArrivalStation");
document.getElementById("getStationDesc").value=stationName;
window.localStorage.setItem("lastDepartureStation",stationName);
callWebservice(stationName.substring(0,3));


}

}

function stringTruncate(args){
console.log(args)
// var args = args || {},
var length = args.length || 5,
tail = "";
if(args.length >=4)
{
tail = args.tail || '...';
}
return args.substring(0,4) + tail;
}


function refeshdata(stationCode){


document.getElementById("getStationfilter").value="All"

console.log(" Web service .............");
console.log(stationCode);
var pl = new SOAPClientParameters();
var parameter1 = stationCode;
pl.add("crsCode", parameter1);
SOAPClientfilter.invoke(WSDLURL, "getDepartureStationDashboard", pl, true,departureStationDashboardResponse);


}


function callWebservice(stationCode){

document.getElementById("getStationfilter").value="All"
document.getElementById('loadingImg').style.visibility = "visible";
console.log(" Web service .............");
console.log(stationCode);
var pl = new SOAPClientParameters();
var parameter1 = stationCode;
pl.add("crsCode", parameter1);
SOAPClientfilter.invoke(WSDLURL, "getDepartureStationDashboard", pl, true,departureStationDashboardResponse);
}


function departureStationDashboardResponse(r,xmlResponse)
{

console.log(xmlResponse);
document.getElementById('loadingImg').style.visibility = "hidden";
var responseXML = xmlResponse.documentElement;
var getDepartureStationDashboardReturn = responseXML.getElementsByTagName("getDepartureStationDashboardReturn");
var RID = responseXML.getElementsByTagName("RID");

var platformNo = responseXML.getElementsByTagName("platformNo");
var stationName = responseXML.getElementsByTagName("stationName");
var toSchArrival = responseXML.getElementsByTagName("toSchArrival");
var toExpArrival = responseXML.getElementsByTagName("toExpArrival");
var toc = responseXML.getElementsByTagName("toc");
var schDepart = responseXML.getElementsByTagName("schDepart");
var expDepart = r
ravi1989h 18-Oct-12 3:30am    
Hii don't need this solution...
ravi1989h 18-Oct-12 3:30am    
actually my question is different
Naga KOTA 18-Oct-12 3:32am    
what is problem then
ravi1989h 18-Oct-12 3:35am    
i am creating table at dynamically (web service response), in tavle i create column .in column i have if there is alert in something i want to show error image else correct image , i want to click only error image ,i am not able to do that?
var td4 = document.createElement('td');
var img = document.createElement('img');
img.setAttribute('width', '24');
img.setAttribute('height', '24');
td4.setAttribute('style','width:3%');
td4.setAttribute('align','center');


(function(id) {
img.onclick = function(e) {
e.preventDefault();
e.stopPropagation();
// now it will alert the id (what is the i of the for-loop):
********here i need some condition ********
alert(id);
};
}(i));
if(serviceAlertPresent[i].firstChild.nodeValue == 'false'||otherAlertPresent[i].firstChild.nodeValue == 'false')
{
img.src='images/correct-icon.png';

//td4.innerHTML = "<img src=\"images/correct-icon.png\" width=\"20\" height=\"20\" />";
td5.innerHTML="";
}
else
{
img.src='images/error-msg.png';
//td4.innerHTML = "<img src=\"images/error-msg.png\" width=\"20\" height=\"20\" />";
td5.innerHTML=expDepart[i].firstChild.nodeValue ;
}

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900