Avatar of Wayne Barron
Wayne Barron
Flag for United States of America asked on

asp classic hide after successful submit

Hello All;

I am submitting my page using AJAX.
I know how to HIDE the button using the <div> tag, upon button click.
However, I need to ONLY hide the button on a successful submit.

OK, the Code on the process page is something like this.

if Field1="" then
response.write "Please fill in Field Area"
else
response.write "Thank you, the form has been submitted successfully"
end if

Open in new window


So, what needs to happen here, is, the script needs to see if the form has been success and if so, [Hide] or [Disable] the submit button, this way, the person cannot accidentally make another submission.

Thank You
Carrzkiss
ASPJavaScriptAJAX

Avatar of undefined
Last Comment
Wayne Barron

8/22/2022 - Mon
Wayne Barron

ASKER
I found this.
http://docs.jquery.com/Plugins/Validation
(The first example)

However, I cannot get it to work with my site.
Of which is loading inside of a "fancybox"
sammySeltzer

Hi @carrzkiss,

I guess my question is, how do you define "successful" submission?

You can use this to prevent duplicate submission by disabling submit button after the submit button has been clicked once:


<script type="text/javascript">
var submitted = false;

function CheckSubmitted()
{
    if (submitted == true) { return false; }
    else { submitted = true; return true; }
}
</script>

<form name="form1" action="post" onSubmit="return CheckSubmitted();">
    .......
</form>

Open in new window


I have also used the code in this link:

http://www.4guysfromrolla.com/demos/DontSubmitTwice2.htm and it works pretty good.
Wayne Barron

ASKER
Hey Sammy

In the case I have right now, I check to see if all the fields have data in them.
If they do, then the form post back a message to the <div> letting the user know, that the information has been submitted successfully.

The only way I would be able to use that method, is if somehow it was on the processing page, and would do a post back to the form page, and then disable the button.

I could use the <div> to hide the button, or the fields, however, if they do not fill out everything, then they will have to load another form, in order to complete the fields.

As for the link, that is sweet, seen them before, however, that is not going to work, unless I can somehow do a post back to the form page.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
sammySeltzer

Ok, so you have 2 situations, unless I am reading it wrong.

1, to ensure required fields are not blank. That, I am sure you are able to handle easily with js.
2, to ensure all fields have data?

Why not make it easy on yourself by creating a preview page?

Users click the Submit button and a preview page pops up.

Users are able to review their entries for correctness, etc.

If all is well, then, then clik submit again.

This time, the example/link I posted become useful.

Just my 2 crusty coppers.
Michel Plungjan

If you use Ajax, you need to check the reply.

Here is how in jQuery which has the easiest Ajax.

$("form").on("submit",function(e) { 
    e.preventDefault();
    var querystring = $(this).serialize();
    $.get(this.action+"?"+querystring,function(data) {
       if (data.indexOf("thank") !=-1) $("this").hide();
    });
});

Open in new window

Michel Plungjan

With the validation you would have something like

$(document).ready(function(){
  $("#myform").validate({
    var $form = $(this);
    submitHandler: function(form) {
      var querystring =$form.serialize();
      $.get(form.action+"?"+querystring,function(data) {
        if (data.indexOf("thank") !=-1) $.fancybox.close();
      });
    }
  });
});

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
@Sammy.
Having a Preview page would not be something that I would like to have in the site.
It is a fast pace site, that needs the information submitted quickly.

@mplungjan
I do not know a lot about jquery, so I am slightly lost as to what this does.
I see where it is closing the FancyBox, that is good "Maybe" as long as it is letting the person know that first.

How can I test this script out, where would I put it at?
Michel Plungjan

I would need to see the rendered HTML.
You need to include jquery library and then add my script to the head

You can show the data returned befor closing or show it on the page after closing - that  is up to you.
hielo

Assuming you are using xmlhttpPost() from your ajaxsbmt.js file, you will need to define a new function named updatepage().  The reason for this is that your xmlhttpPost() always calls a function named updatepage() once it is done.  In your ajaxsbmt.js, that function does a very specific task.  What you are trying to do is something completely different, so you will need provide a different definition for it - ex:
<!-- "import" your js file -->
<script type="text/javascript" src="js/ajaxsbmt.js"></script>

<!-- now provide a new function named updatepage -->
var updatepage = function(serverResponse, contentDiv)
{
   //here you do whatever you want with the response

   if( 'Thank you'==serverResponse.substring(0,9) )
  {
     //now disable the button.  Suppose you have
     //<input id="mainButton" ...>
     document.getElementById('mainButton').disabled=true;    
  }
  document.getElementById(contentDiv).innerHTML=serverResponse;
};

Open in new window

This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Wayne Barron

ASKER
Hello Hielo.
Do I just drop it in like you have it, or do I have to create the

function()
For it first?
hielo

>>Do I just drop it in like you have it
Yes.  On my post, I already re-created the function for you AFTER importing ajaxsbmt.js.

Again, your original ajaxsbmt.js contains a function named "updatepage".  Thus, on line 2 of my post I am importing your original definition of "updatepage", but then on line 5 I am creating a new definition for updatepage.  The last definition is the "active/valid" definition.

Regards,
Hielo
Wayne Barron

ASKER
OK, I added the code to my js file.
Then I changed the ID of my button to: mainButton
And it does not work, I can continue to submit the button, even after the first one went in.

The js file looks like this now.

function updatepage(str,responsediv){
    if( 'REDIRECT-TO: '==String(str).substring(0,13).toUpperCase() )
      top.location.href=str.substring(13);
    else
        document.getElementById(responsediv).innerHTML = str;
}
var updatepage = function(serverResponse, contentDiv)
{
   //here you do whatever you want with the response

   if( 'Thank you'==serverResponse.substring(0,9) )
  {
     //now disable the button.  Suppose you have
     //<input id="mainButton" ...>
     document.getElementById('mainButton').disabled=true;    
  }
  document.getElementById(contentDiv).innerHTML=serverResponse;
};

Open in new window


Button
 <input class="UpFF" id="mainButton" type="submit" name="Submit" value="Insert <%=Mach%>"  tabindex="9"/>

Open in new window

⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
hielo

>>OK, I added the code to my js file.
Well, that should solve your problems as long as your server script actually responds with with content that begins with "Thank you" (case sensitive) (if you want to make the case insensitive, change it to:

if( 'THANK YOU'==serverResponse.substring(0,9).toUpperCase() )

Open in new window


Do you have a "test" page?
Wayne Barron

ASKER
Here is the test page (It will show the time, everytime that you click the submit button)
http://ee.cffcs.com/Q_27976408/Q_27976408.asp
And the code
http://ee.cffcs.com/Q_27976408/Q_27976408.zip

Carrzkiss
ASKER CERTIFIED SOLUTION
hielo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Wayne Barron

ASKER
Nice.
This is what I have, using your suggestion at the bottom.

http://ee.cffcs.com/Q_27976408/Q_27976408.asp

(Same as other thread, once I get my points back, I will close this out and award you the points)

It is always nice, to be able to continue using what I have, instead of changing to other codes all the time.
Thanks Hielo
You Rock!

Carrzkiss
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
hielo

>>It is always nice, to be able to continue using what I have
Which is why I'm surprised you took the approach described on post ID: 38735114
"OK, I added the code to my js file."

By making that change in the ajaxsbmt.js file, if you have other projects that are importing that file, then those will most likely stop working as expected (since you change the original function definition of updatepage).  What you should have done is to keep ajaxsbmt.js exactly as it was, and then on the <head> of Q_27976408.asp you create a script tag that includes your new defintion for updatepage() (lines 7-18 of Post ID: 38735114).
Wayne Barron

ASKER
I just did exactly as you suggested.
Now the ajaxsbmt.js file is back to the way it was.
And the added script is in the header.

Thanks for the heads up on that one Hielo.
Going to get some rest, have a long couple of days coming up.

Take Care
Carrzkiss
Wayne Barron

ASKER
Awesome Work again Hielo.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.