Click here to Skip to main content
15,861,172 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi Geniuses,

If I am hard coding int JavaScript, it is working but when I am using switch() it is not working. What's wrong in my code. Could any genius help me please!

html
=======
<img src="Images/btn_off_lookup.gif" id="Img1" name="ComplainantID" class="lu" lookuptypeicons="/Images/ico_16_8.gif" otypename="Participant" lookupstyle="single" onclick="OpenLookup(); />

Javascript (working.. Hrad coding)
========================
function OpenLookup()
{
o=event.srcElement;
var sPath;
switch(o.otypename)
{
case "Participant":
sPath = "ParticipantList.aspx";
break;
case "Mediator":
sPath="MediatorList.aspx";
break;
}
sPath="MediatorList.aspx?lookup=Y&fieldname=" + o.name;
openStdWin(sPath,"",700,500,"dependent=yes,resizable=yes");
}

Javascript (Not Working)
===========================
function OpenLookup()
{
o=event.srcElement;
var sPath;
switch(o.otypename)
{
case "Participant":
sPath = "ParticipantList.aspx";
break;
case "Mediator":
sPath="MediatorList.aspx";
break;
}
sPath=sPath+"?lookup=Y&fieldname="+o.name;
openStdWin(sPath,"",700,500,"dependent=yes,resizable=yes");
}

Any Suggestion or idea is highly appreciated.

Thanks in advance,
Shafik
Posted
Updated 18-Jun-15 6:15am
v3

1 solution

A number of points:
1. Typo missing closing "
onclick="OpenLookup()"; 

2. The switch condition should be:
switch(o.getAttribute("otypename"))

3. Lastly, try to change this so that it works on all browsers.
var o= event.target || event.srcElement;
 
Share this answer
 
v2
Comments
[no name] 18-Jun-15 13:10pm    
When I posted, Unfortunately I did the Typo. But "switch(o.getAttribute("otypename"))" ... this is absolutely working fine. Thank you so much for your kindness. I can not give any return but I am praying for you so that you will get success in your every step.

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