aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Disabling a submit button. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Disabling a submit button." Watch "Disabling a submit button." New topic
Author

Disabling a submit button.

Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Hello all, I have an jsp page which submits some information to another jsp, my question is: How do I avoid user to click the submit button again on page 1 if he uses the back button??
Could I use javascript to avoid the use of the back button?
how?
Can I use javascript to avoid the user click again on submit button of page 1?
Thank you . . . .
A1ien51 CNEUFOs
Greenhorn

Joined: Nov 05, 2001
Posts: 16
Wel you can use cookies to see if the form has already been submitted or you can use meta tags to expire the page if the user clicks on the back link.
Hope this helps
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
How do I use the meta tag ?
<META HTTP-EQUIV="expires" content="0">
what should I put in content ??
Originally posted by Zkr Ryz:
Hello all, I have an jsp page which submits some information to another jsp, my question is: How do I avoid user to click the submit button again on page 1 if he uses the back button??
Could I use javascript to avoid the use of the back button?
how?
Can I use javascript to avoid the user click again on submit button of page 1?
Thank you . . . .

A1ien51 CNEUFOs
Greenhorn

Joined: Nov 05, 2001
Posts: 16
you can put this code on the page that you do not want people to come back too.
<script>
var where = "thepageBEFORE.html";
if (document.referrer!=where){
window.location.replace('somepagetogoto.html');
}
</script>
see if you can play around with that
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
I thought I could but I have two frames and document.referrer is always giving me the same url.
I tried parent.frames[1].document.referrer but is the same . . .
Is there another way to avoid the user click again in the button?
I tried meta tag also, it suppose to send me a "your page has expired " or something but it doesn't.
<META HTTP-EQUIV="expires" content=" Tuesday, 06-Oct-01 14:00:00 CST">

Thanks anyway.
I'll keep trying.
A1ien51 CNEUFOs
Greenhorn

Joined: Nov 05, 2001
Posts: 16

window.location.replace('page.html');

You have to change that to work with the frames
I think that keeps the page from going into history.
You are making me think
hehhe
Zkr Ryz
Ranch Hand

Joined: Jan 04, 2001
Posts: 187
Ok, I finally did it!!!.
heres what I did.
<input type="button" name="dammButton" onClick="goNext( this )">
<script>
funtion goNext( btn){
btn.form.submit();
document.write("<META HTTP-EQUIV=\"REFRESH\" CONTENT=\"0;URL=http://goHome.com/home>");
}
</script>
When the user clicks the button the page do what it should submit the form, and before it leaves write to the document the http meta tag refresh with content of 0 that means refresh immediately and the url to go home, then on page 2 whan user go back he found a page with that information alone and . . .
finally get redirected...
Now I got to see if it works on NS4+
)
Thanks a lot A1ien51 CNEUFOs, for the inspiration.
P.S. Stopt thinking !!!

Originally posted by A1ien51 CNEUFOs:

window.location.replace('page.html');

You have to change that to work with the frames
I think that keeps the page from going into history.
You are making me think
hehhe


ziqiang wu
Greenhorn

Joined: Jun 18, 2001
Posts: 25
hi ZKr:
base on your new requirement, I believe there are several way to solve this problem. but I think a good solution should hide any logic problems and always make clents not realize their wrong operation, but always get correct results.
I dont like make any unexpected things happened to clients, for example, if client click back button or something else, then they are kicked out of "current status", and forced to be in a unexpected "status".
one way I think should meet your new requirements not by javascript.
in the second page, assumed that you get information(String) by these method.

//initiate, get value and count how many value you got
int count=0;
String ss1=request.getParameter("information1");
count++;
String ss2=request.getParameter("information2");
count++;
.
.
.
Vector forSave=new Vector(), savedInfo=new Vector();
//save all coming information in vector forSave every time
for(int i=1; i<=count; i++)
forSave.addElement("ss"+i);
//if this is first time, no old value to compare, but need to save these value for comparation next time

if(session.getAttribute("savedInfo")==null && request.getParameter("submit")!=null)
{
save ss1, ss2, ss3....;
session.setAttribute("savedInfo", forSave);
}
//if this is not first time, you need get old saved value to compare with current value. only those value that never be saved before can be saved this time
if(session.getAttribute("savedInfo")!=null && request.getParameter("submit")!=null)
{
savedInfo=(Vector)session.getAttribute("savedInfo");
for(int i=0; i<forSave.size(); i++)
for(int j=0; j<savedInfo.size(); j++)
if((String)forSave.get(i).equals((String)savedInfo.get(j)))
{
forSave.removeElement((String)forSave.get(i));
break;
}
else
if((j+1)==savedInfo.size())
savedInfo.addElement((String)forSave.get(i));
//right now, every string in vector forSave never saved before

if(forSave.size>0)
{
retrive information form vector forSave and save them to database or what ever;
}
//save vector savedInfo in session for comparation next time
session.setAttribute("savedInfo", savedInfo);
}
this code is just showing an algorithm to compare coming infomation with old saved infomation. only those information never saved before can be saved only this time.
hope it is helpful for u
Ziqiang Wu
Java Developer
Wellogix, Inc.
 
jQuery in Action, 2nd edition
 
subject: Disabling a submit button.