Pop up window in ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • F159753
    New Member
    • Apr 2008
    • 31

    Pop up window in ASP

    Hi,

    I would like to define a function in ASP which poped up a window and asking me if I am sure?
    something like:

    SUB ConfirmDelete()

    ...popup confirmation window

    return (answer)

    END SUB


    Confirmation=Co nfirmDelete()

    AND I don't want to use JavaScript. Do you have any idea how should I do it?

    Regards,
    FF
  • jeffstl
    Recognized Expert Contributor
    • Feb 2008
    • 432

    #2
    Just make a link or button open a new window

    Code:
    <a href="mylink.asp" target="_blank">Save</a>
    Then on the mylink.asp page just redirect it to itself after they hit "yes" for sure, and save\delete whatever action, or if its no simply redirect them back to the original page I guess.

    If you are trying to trigger this popup from a button click then you may need to change where your form is submitting. You could use the actual submit page as your confirmation page too.

    Comment

    • F159753
      New Member
      • Apr 2008
      • 31

      #3
      how about if I use Javascript? it is not working yet!

      Code:
       
      <script LANGUAGE="JavaScript">
      <!--
      function confirmDelete()
      {
      var agree=confirm("Are you sure you want to delete The Entire Expense?");
      if (agree)
      	return true ;
      else
      	return false ;
      }
       
      -->
      </script>
       
      <input type='submit' value='Delete' onClick=location.href='ContractorExpenseDelete.asp';return confirmDelete();>

      Comment

      • jeffstl
        Recognized Expert Contributor
        • Feb 2008
        • 432

        #4
        Code:
        <script LANGUAGE="JavaScript">
        <!--
        function confirmDelete()
        {
        var agree=confirm("Are you sure you want to delete The Entire Expense?");
        if (agree)
        window.location="http://www.site.com/mypage.asp?confirm=yes"
        else
        window.location="http://www.site.com/mypage.asp?confirm=no"
        }
        
        -->
        </script>
        
        <input type='submit' value='Delete' onClick='return confirmDelete();'>
        Problem here is which expense are they deleting and how does mypage.asp know which expense to delete? Things you might want to think about.

        Comment

        • F159753
          New Member
          • Apr 2008
          • 31

          #5
          Perfect, one step ahead:)

          the small window now pops up and asking if I am sure ? but when I click "yes" then it doesnt do anything. here is the function I have for it:
          Code:
           
          <script LANGUAGE="JavaScript">
          <!--
          function confirmDeleteLine()
          {
          var agree=confirm("Are you sure you want to delete this line of Expense?");
          if (agree)
          	{
           
          	window.location="ContractorExpenseEditDeleteItem.asp?EIID="&strExpenseItemID;
          	return true;
          	}
          else
          	{
          	alert("no")
          	window.location="ContractorExpenseEdit.asp";
          	return false;
          	}
          }
           
          // -->
          </script>
           
           
           
           
           
          <input type='submit' value='Delete' onClick='return confirmDeleteLine();'>
          do you know what did I put wrong in JavaScript?

          Regards,
          FF

          Comment

          • jeffstl
            Recognized Expert Contributor
            • Feb 2008
            • 432

            #6
            Actually it does do something. It is a javascript error saying strExpenseItemI D is undefined.

            Which this may be where one of your main misunderstandin gs are.

            ASP code is execute and stored on the web server, javascript runs in the user's browser.

            You cannot have a .asp variable passed to a javascript function, because that variable is only "known" on the server.

            You have to submit a form to a .asp page to process your delete (passing the strExpenseItemI D via the form or a hidden control on the form).

            You only want to use the javascript for validation. If you return a true or a false you can keep the form from being submitted and utilize this for your validation of the delete

            In other words your form action should be set to ContractorExpen seEditDeleteIte m.asp?EIID=<%=s trExpenseItemID %>

            Then your submit button should call your javascript and return true or false

            I believe you will find the below code to work exactly as you expect

            Code:
            <script LANGUAGE="JavaScript">
            <!--
            function confirmDeleteLine()
            {
            var agree=confirm("Are you sure you want to delete this line of Expense?");
            if (agree)
            {
             
            return true;
            }
            else
            {
            return false;
            }
            }
             
            // -->
            </script>
             
             
             
             
            <form action="ContractorExpenseEditDeleteItem.asp?EIID=<%=strExpenseItemID%>" method="post">
            <input type='submit' value='Delete' onClick='return confirmDeleteLine();'>
            </form>

            Comment

            • jeffstl
              Recognized Expert Contributor
              • Feb 2008
              • 432

              #7
              If you don't know what strExpenseItemI D will be then you need to pass it with a hidden form control or something possibly that a user enters or gets filled in on the form from a drop down

              Code:
              <input type="hidden" value="<%=strExpenseItemID%>" name=txtExpense>
              Something like that or you need to ensure that the expense id is passed in some way from the form.

              Comment

              • F159753
                New Member
                • Apr 2008
                • 31

                #8
                I put the variable in a Session variable in ASP and it is working perfectly:)

                Thank you so much for your help:)

                Have a nice day.

                Comment

                Working...