Click here to Skip to main content
15,883,809 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Hi Geniuses,

I have written JavaScript function which is calling from html but it is not working. below is my html and JavaScript function.So it is throwing the 404 exception.

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();">

JS
===
C#
function OpenLookup() {
        //window.open(sPath, '', 'dependent=yes,width=900,height=650,resizable=yes');
        //alert('Come here');
        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");
    }


Could you please tell me why it is not working.

Any idea or suggestion is highly appreciated.

Thank You!
Shafik
Posted
Updated 17-Jun-15 8:48am
v3
Comments
ZurdoDev 17-Jun-15 15:10pm    
404 means the url is wrong.
Mohibur Rashid 17-Jun-15 20:21pm    
What browser are you using? Try chrome or firefox. If chrome press ctrl+shift+j . New window or pane will be opened. Clivk on the Console tab. Now try clicking your image. Read tge error on the pane. If you do not see an error directly call your function from your console window and see what result you can see. Come to us again if you have trouble.

1 solution

Debug it. What, even alert('Come here') did not work? If you really copied all text correctly, it should work.
One possible problem is that you have lexical error elsewhere. In case of such error, the whole JavaScript, even correct fragment, may not work. JavaScript is not a pure interpreter (surprise?!), the implementation can have pre-processing where the lexical error can fail the whole thing without any exceptions.

First, of all, you can simplify all code down to some absolute minimum and make sure onclick handler does work. It will. Then, you can take different routes. First of all, use JavaScript debugger. If it seems to be difficult (there are problems with different set-ups), you can try to add code back by small pieces, until the problem re-appears. This is a hard way to localize it. If that seems to be difficult, I have my own "secret weapon": put all code in string use JavaScript eval on this string, sandwiched with try-catch block. This is a trick to catch lexical errors as exceptions, not only "usual" exceptions. I described this technique in detail in this section of my article: JavaScript Calculator, 5. Handling Lexical Errors.

[EDIT: In response to the discussions in comments]

What are you talking about? This is a minimal code, it works:

HTML
<html>
   <head>
      <title>Click handler should work!</title>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <script>
         function clickHandler() {
            alert('click handler works!')
         }
      </script>
   </head>
<body>

<img src="nothing certain" onclick="clickHandler()" width="100", height="100" />

</body>
</html>


So, you cannot tell us that onclick doesn't work. Start with this code sample and add your code. Or show your complete code (minimize it as much as your can). You are doing something wrong on some elementary level. Maybe script is misplaced (where is it?) maybe you misspell something. Analyze the situation on a comprehensive way.

—SA
 
Share this answer
 
v3
Comments
[no name] 17-Jun-15 15:16pm    
Hi Sergey,
I really appreciate and thankful to you for your quick reply. The problem is onclick is not working. I put alert message but it is not coming into JavaScript function. I have only two hours to submit my whole project. Reality I am stuck only in this position. I am reading your article.

Thanks again,
Shafik
Sergey Alexandrovich Kryukov 17-Jun-15 15:25pm    
Then start using some of my recommendations. onclick certainly does work, there is no doubt about it. Write the simplest code from scratch and you will certainly get it. Checkup everything, such as spelling...
—SA
[no name] 17-Jun-15 15:30pm    
function OpenLookup() {
//window.open(sPath, '', 'dependent=yes,width=900,height=650,resizable=yes');
debugger
try {
alert('Come here');
} catch (e) {
e.message();
}
//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");
}

No luck cursor is not coming to this place.I am getting 404 pop up exception . Please help me.
[no name] 17-Jun-15 15:39pm    
Detail Error Message:

Detailed Error Information:



Module
IIS Web Core

Notification
MapRequestHandler

Handler
StaticFile

Error Code
0x80070002



Requested URL
http://localhost:59037/undefined?lookup=Y&fieldname=ComplainantID

Physical Path
C:\Workspace\CaseTracking\CaseTracking\undefined

Logon Method
Anonymous

Logon User
Anonymous

Request Tracing Directory
C:\Users\mislam8\Documents\IISExpress\TraceLogFiles\CASETRACKING(4)
Sergey Alexandrovich Kryukov 17-Jun-15 15:47pm    
What are you talking about? In your sample the should not be any cursor. What cursor? There is a mouse cursor and not a text caret.
Check up everything in a comprehensive way. Please see my update to the question. This event handler always works, you cannot tell us it doesn't.
—SA

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

  Print Answers RSS


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