• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 666
  • Last Modified:

object required javaScript error embedded into ASP

Hello Everyone, I have a page which posts to itself.  The purpose is to set the status, in other words change update the status on the database depending on which button is clicked: Open or Close

However, I get a JavaScript error:

Object required

 Line: 192


This is a line that has nothing to do with the code below, but I do have a lot of include files so I really do not know where line 192 is coming from& I do know that there is something wrong with this particular code because I you remove it the application works perfectly, but we cannot remove it& We had it so that the status would update correctly but they would update just by opening the page, what I need is the status to update when the correct button is clicked&. That is because if a person visits this page and does NOT click the button, then we do NOT want the form to update, it would be a huge error&. That is why I really need your help with this you and its particularly important that just visiting this page does not update the status& If you want I can show you the entire code, but its over 2000 lines long&


If it would be better to have the code post to another page, a little page that opens in a new window and says your page was correctly submitted, I would be willing to do that also, but as far as I know whether a page posts to itself or a diff page, the code is pretty much the same, its still request.form&The idea is that when the user clicks OPEN the form should OPEN, and the status should change to (OPEN) but the OPEN button should disappear and be replaced by the CLOSED button.  This is because now that the form is open the next step would be to close it, and vice versa& There is a button that can stop this open and close from happening, and if that button is clicked, then BOTH buttons disappear, but that part works, so I do not need help with it&.  Can U help me figure this one?

NOTE: This page posts to itself, I think when it does this something is not working properly because we are clicking submit buttons and yet they do not make a difference, they do not call the ASP code and to test it we did a response.write request.form("hideOpenBtn") and we did not get any value, not even 0 which is the default value for this hidden variable

CODE:


<form action="52-readOnly.asp" id="OPICForm" name="OPICForm" method="post" onSubmit="return ValidateSubmit();">

<input name="hideOpenBtn" type="hidden" value="0" />

<script language="JavaScript" type="text/JavaScript">
//Angie H.  ------   OPENS THE APPLICATION
      function openBtn(){
            document.OPICForm.hideOpenBtn.value = 1;
//**********************************************************************
//In JavaScript confirm shows OK and CANCEL in the pop up, which is exactly what we need, if they click OK, then the update should take place, if they click Cancel than nothing should happen&
//**********************************************************************


            confirm("Are you sure you want to OPEN this form? If Yes, click OK, then click the Return to Registrations/Applications Report link at the top of the page.");
            document.getElementById("of").style.visibility = "hidden";
            document.getElementById("cf").style.visibility = "visible";            
            return false;
      }
     
      function closeBtn(){
            document.OPICForm.hideOpenBtn.value = 2;
           
            confirm("Are you sure you want to CLOSE this form?  If Yes, click OK, then click the Return to Registrations/Applications Report link at the top of the page.");
            document.getElementById("cf").style.visibility = "hidden";
            document.getElementById("of").style.visibility = "visible";
            return false;
      }
     
     
</script>

<div name = ocButtons id = ocButtons style="VISIBILITY: visible">
<table width="100%" border="0" cellspacing="1" cellpadding="1">
  <tr><td>
<% IF IStatusID >3 THEN %>
  <% IF (IStatusID =4 OR IStatusID =5) THEN %>
    <input type = "submit" value="&nbsp;&nbsp;Close Form&nbsp;&nbsp;" name = "cf" id = "cf" type="button"  onClick = "closeBtn(); "/>&nbsp;
  <% ELSE %>
    <input type "submit" value="&nbsp;&nbsp;Open Form&nbsp;&nbsp;" name = "of" id = "of" type="button"  onClick = "openBtn(); " />&nbsp;
  <% END IF %>
<% END IF %>
      </td>
  </tr>
</table>
</div>
<%
if(request.form("hideOpenBtn") = 1) then
      objConn.execute("UPDATE Application SET FK_ApplicationStatusID=6, Submitted_ts='" & now() & "' WHERE PK_ApplicationID=" & iApplicationID)
elseif(request.form("hideOpenBtn") = 2) then      
      objConn.execute("UPDATE Application SET FK_ApplicationStatusID=5, Submitted_ts='" & now() & "' WHERE PK_ApplicationID=" & iApplicationID)
end if
%>
0
Gemini532
Asked:
Gemini532
2 Solutions
 
Pravin AsarPrincipal Systems EngineerCommented:
Since you are talking about multiple includes, I can suggest to have error handler for a page..
Add this a the beginning of the page, before any javascript run/execution takes place.

Try the following code,
This fix helps.
Good Luck !
-PA


<html>
<head>
<title>Catch error </title>
</head>

<body>
<script language="javascript">
function handleErr(err)
{
txt="There was an error on this page.\n\n"
txt+="Error: " + err + "\n"
alert(txt)
return true
}
onerror=handleErr

alert ('Message  ' + myvar);
</script>
                             
</body>
</html>
0
 
stanscott2Commented:
In this part of the HTML:

<% IF (IStatusID =4 OR IStatusID =5) THEN %>
    <input type = "submit" value="&nbsp;&nbsp;Close Form&nbsp;&nbsp;" name = "cf" id = "cf" type="button"  onClick = "closeBtn(); "/>&nbsp;
  <% ELSE %>
    <input type "submit" value="&nbsp;&nbsp;Open Form&nbsp;&nbsp;" name = "of" id = "of" type="button"  onClick = "openBtn(); " />&nbsp;
  <% END IF %>

With the first INPUT tag, you declare the type as "submit", but later declare the type as "button" in the same tag.

With the second INPUT tag, you don't declare the type as "submit" properly (you have type "submit", not type="submit"), and then you again declare the type as "button" in the same tag.

You aren't using the confirm method correctly.  It's "naked" -- instead, it should be used as part of an IF statement, like this:

if  (confirm("Are you sure you want to OPEN this form? If Yes, click OK, then click the Return to Registrations/Applications Report link at the top of the page.")) {
       do something;
} else {
      do something else;
}

In the code you've given, the confirm box comes up, but nothing depends on what the user clicks, so execution just continues on the next line.

One more thing.  It's not clear from the HTML you've given, but make sure you're closing all tags properly, such as <form>, which should have </form> later on.  If your HTML isn't structured properly, the Javascript won't be able to find the correct object in the DOM.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now