Solved

asp classic hide after successful submit

Posted on 2012-12-23
19
1,089 Views
Last Modified: 2013-01-10
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
0
Comment
Question by:Wayne Barron
  • 9
  • 5
  • 3
  • +1
19 Comments
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38716851
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"
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 38717581
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.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38717596
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.
0
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 38717644
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.
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38717855
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

0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38717906
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

0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38717970
@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?
0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 38718014
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.
0
 
LVL 82

Expert Comment

by:hielo
ID: 38725885
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

0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Author Comment

by:Wayne Barron
ID: 38734341
Hello Hielo.
Do I just drop it in like you have it, or do I have to create the

function()
For it first?
0
 
LVL 82

Expert Comment

by:hielo
ID: 38735011
>>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
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38735114
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

0
 
LVL 82

Expert Comment

by:hielo
ID: 38735147
>>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?
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38735368
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
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 38735408
>>It will show the time, everytime that you click the submit button
That's exactly where your problem lies.  Currently, your Insert.asp returns

Hello,you just clicked the button<br />You clicked at this time: XXXX

But the code I gave you expects your Insert.asp to generate output that begins with "Thank You".  So if you were to change your output to:

Thank You.  Hello,you just clicked the button<br />You clicked at this time: XXXX

Then the button should become disabled.

Perhaps what you should be doing is generate an HTML comment with OK when the POST processing is successful - ex:
<%
Response.Write "<!-- OK -->Hello,you just clicked the button<br />You clicked at this time: XXXX"
Response.End
%>

Open in new window


and change the javascript to test for that specific (successful) output:
if( '<!-- OK -->'==serverResponse.substring(0,11).toUpperCase() )

Open in new window


If you encounter errors while processing the POST request and generate any output that does not start with <!-- OK -->, then it can be interpreted as a failed POST processing attempt -ex:
<%
Response.Write "Problems processing your request"
Response.End
%>

Open in new window

Then the above would not disable the button.  Personally I would use
<!-- OK -->XXXX for successful POST processing and
<!-- !OK  -->XXX for unsuccessful POST processing ( if I actually see "!OK", that indicates there was an actual attempt at processing the POST request, but that it failed ).

Using the HTML comment would hide whatever message you are trying to insert into the div with your ajax post processing calls.
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38735448
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
0
 
LVL 82

Expert Comment

by:hielo
ID: 38735518
>>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).
0
 
LVL 30

Author Comment

by:Wayne Barron
ID: 38735589
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
0
 
LVL 30

Author Closing Comment

by:Wayne Barron
ID: 38763029
Awesome Work again Hielo.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now