Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Session Variable Usage

Status
Not open for further replies.

gio2888

Technical User
Oct 26, 2000
64
US
Hi, I have an asp page that has 2 submit buttons, it says "Approve" and "Disapprove". When either button is clicked it goes to a different page saying that the person either approved it or disapproved it and an email is sent to another person notifying their decision. But when the back button is clicked, it allows the person to click the buttons again and another email is sent. I want to make it to only allow the person to only submit once. Is there anyway I can check that the page has already submitted and that the second time you click on it, it will pop a message telling the person that it can only be clicked once. My co-worker told me to use a session variable, but I tried many times and it doesn t work. I don t want to bother her cause I asked her alot already on this...can someone help me?

this is what I kinda have:

Session("submitted") = request("submit")
k = Session("submitted")

response.write(k)

if isEmpty (Session("submitted")) then
msgbox "You have already submitted your decision."
end if

%>

<script language=&quot;JavaScript&quot;>



function check(){

if (document.form.op.value != Session(&quot;submitted&quot;)){
alert(&quot;You have already submitted your decision.&quot;);
return false;
}

return true;

}
</script>

 
function check(){

if (document.form.op.value != Session(&quot;submitted&quot;)){
alert(&quot;You have already submitted your decision.&quot;);
return false;
}

this swrong as you are putting server side code on the client, change to:

if (document.form.op.value!=&quot;<%=Session(&quot;submitted&quot;)%>&quot;){
alert(&quot;You have already submitted your decision.&quot;);
return false;
}

 
You can do this using client side scripting. When the button 'Submit' is pressed a client side script is executed that disables the submit button. Then the script submits the page. If this response was usefull to you, please mark it with a Star!
 
and what happens if the user reloads the page - the submit button is enabled again! The submit status needs to be held on the server either in a Session variable as above or held in a db along with the user info
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
sjravee, that still didn t work...I clicked on back and then I clicked the either button, and I still got the email notification.

Jantie78, where can I look up the code for disabling the submit button?

Thanks to the both of you!
 
So Fester, how can I make sure or force that the submit only happens once?
 
the page that accepts the form data should set a Session variable to record that the form has been submitted

Session(&quot;submitted&quot;) = &quot;done&quot;

the page that has the FORM should also have a javascript validation function in the <HEAD> section

Code:
<SCRIPT LANGUAGE=&quot;JAVASCRIPT&quot;>
var submitted = &quot;<%=Session(&quot;submitted&quot;)%>&quot;;

function Validate()
{
  if (submitted == &quot;done&quot;)
  {
    alert(&quot;You have already submitted this form&quot;);
    return false;
  }
  else
    return true;
}
</SCRIPT>
</HEAD>

<BODY>

<FORM ACTION=&quot;formsubmit.asp&quot; onSubmit=&quot;return Validate();&quot;>
rest of FORM stuff
Tony
reddot.gif WIDTH=400 HEIGHT=2 VSPACE=3

 
Thank You EVERYONE of YOU for your help, deeply appreciated!

 
So please mark our responses with a star... If this response was usefull to you, please mark it with a Star!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top