Link to home
Start Free TrialLog in
Avatar of subgenius
subgenius

asked on

ASP page with javascript validation

This is continued from https://www.experts-exchange.com/questions/20544030/how-to-pass-user-input-value-to-a-new-web-page.html

I have this code working now and would like to have a confirmation page show after this page is submitted.  As it is now, this is what shows after Submit:

form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com

gladxml had the comment "'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form"  but I'm not sure how to use server.transfer to call the next page and pass the values i want to show.
*************************************************

<%
if request.form("form_ok") = "True" then

   Response.Buffer = true
   dim cnn,rst
   dim strConn
   dim rscheck

   set cnn = Server.CreateObject("ADODB.Connection")
   cnn.open "Provider=OraOLEDB.Oracle; Data Source=xxx; User Id=xxx; Password=xxx"

      set rscheck = Server.CreateObject("ADODB.RecordSet")
     
      'KIndly double check if this is the sql is correct...
   strQuot=Chr(39)

          sql1 = "SELECT * FROM tablename WHERE email_addr ='" & request("email") & "'"


   set rscheck = cnn.execute(sql1)
     
     if not (rscheck.eof) then


         
   set rst = Server.CreateObject("ADODB.RecordSet")
   strQuot=Chr(39)
   
   sql =  "UPDATE tablename SET " & "firstname =" & strQuot & Request.Form("fname") & strQuot & ", " & "lastname=" & 

strQuot & Request.Form("lname") & strQuot & ", " & "email_addr=" & strQuot & Request.Form("newemail") & strQuot & "WHERE

email_addr=" & strQuot & Request.Form("email") & strQuot
   set rst = cnn.execute(sql)

   
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form


     
     for each fld in request.form
   response.write fld & " = " & request.form(fld) & "<BR>"
   next
   response.end
   
   Response.Write "Record updated"
   response.write "your old email address was: " & request.form("email") & "<BR>"
   response.write "your new email address was: " &  request.form("newemail")

     

else

errmsg = "Please check email address entered... No record found..."

end if

end if
%>

<html>
<head>
<title>
Email Address Update
</title>
</head>
<body>

<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>
<input type="hidden" name="form_ok" value="False">

ENTER  OLD EMAIL ADDRESS<br>
<input type="text" name="email" size="50" value="<%=request.form("email")%>"><%=errmsg%><br>

ENTER NEW FIRST NAME<br>
<input type="text" name="fname" size="30" value="<%=request.form("fname")%>"><br>

ENTER NEW LAST NAME<br>
<input type="text" name="lname" size="30" value="<%=request.form("lname")%>"><br>

ENTER NEW EMAIL ADDRESS<br>
<input type="text" name="newemail" size="50" value="<%=request.form("newemail")%>"><br>

<input type="submit" value="Submit" name="submit"></form>
</body>
<script language="JavaScript">
<!--
function verifyEmail(frmEmailAdd)
{
 invalidChars = " /:,;";


 if (frmEmailAdd == "") {
   return false;
 }
 for (i = 0; i < invalidChars.length; i++) {
   badChar = invalidChars.charAt(i);
   if (frmEmailAdd.indexOf(badChar, 0) > -1) {
     return false;
   }
 }
 atPos = frmEmailAdd.indexOf("@", 1);
 if (atPos == -1) {
   return false;
 }
 if (frmEmailAdd.indexOf("@", (atPos + 1)) > -1) {
   return false;
 }
 periodPos = frmEmailAdd.indexOf(".", atPos);
 if (periodPos == -1) {
   return false;
 }
 if ((periodPos + 3) > frmEmailAdd.length) {
   return false;
 }
 return true;
}

function validate()
{
  if (!verifyEmail(document.inputform.email.value)) {
   alert("Invalid email address... Kindly check old email address");
   document.inputform.email.focus();
   document.inputform.email.select();
   return false;
 }
 if (document.inputform.fname.value == "") {
   alert("You must enter a First Name");
   document.inputform.fname.focus();
   return false;
 }
 if (document.inputform.lname.value == "") {
   alert("You must enter a Last Name");
   document.inputform.lname.focus();
   return false;
 }
  if (!verifyEmail(document.inputform.newemail.value)) {
   alert("Invalid email address... Kindly check new email address.");
   document.inputform.newemail.focus();
   document.inputform.newemail.select();
   return false;
 }

document.inputform.form_ok.value="True";
return true;
}
// -->
</script>

</html>
Avatar of keith_dude
keith_dude

Not sure I understand.  You said you want a confo page showing after submit.   Then, you went on to say that this is what shows after the submit.   So, you appear to be passing the info correctly.    

Are you saying you want to pass this info to yet another page?  
Avatar of subgenius

ASKER

This page submits to itself and displays:
form_ok = True
email = someone@xyz.com
fname = John
lname = Doe
submit = Submit
newemail = jdoe@xyz.com

I want it to display  something more meaningful to the user.  For example:

The record for "someone@xyz.com" has been updated to:
Email Address "jdoe@xyz.com"
First Name     John
Last Name      Doe

In other words, I want to format the output as html on a second page instead of the page submitting to itself.  Or have it submit to itself and display the results as I mentioned above rather that the way it displays now.
Sounds like all you need to do is change your response.write information to show what you are trying to show in your note here.  

==== original code that runs if you are doing an update ===
First you do all your database stuff then you come upon your code here.
 
for each fld in request.form
  response.write fld & " = " & request.form(fld) & "<BR>"
  next
'  response.end 'need to get rid of this until you show all the information you want to show.  
 
  Response.Write "Record updated"
  response.write "your old email address was: " & request.form("email") & "<BR>"
  response.write "your new email address was: " &  request.form("newemail")

---- eof ----
first, let's get rid of that response.end until you show all your information.

Instead of the for each fld in request.form which is just a generic way of showing all the information passed from the form, we can show what you want to show

Such as:

---- BOF ----
Response.write("The record for """ & request.form("email") & """ has been updated to:" & "<BR>")
Response.write("Email Address:" & request.form("newemail") & "<BR>")
Response.write("First Name:" & request.form("fname") & "<BR>")
Response.write("Last Name:" & request.form("lname") & "<BR>")
---- EOF ----

Dan M.
dmstrat@yahoo.com
   
subgenius,

To explain it further...

On the page that you has posted... Kindly delete this lines

=====
'you can do a server.transfer method to show the confirmation on the next page... using for each fld in request.form


   
    for each fld in request.form
  response.write fld & " = " & request.form(fld) & "<BR>"
  next
  response.end
 
  Response.Write "Record updated"
  response.write "your old email address was: " & request.form("email") & "<BR>"
  response.write "your new email address was: " &  request.form("newemail")
=====

then replace it with the line below

====
server.transfer("confirm.asp")
====

Now this will be the second page... which is the
confirm.asp

======just cut and paste and save this as confirm.asp
<%
    for each fld in request.form
  response.write fld & " = " & request.form(fld) & "<BR>"
  next
  response.end
 
  Response.Write "Record updated"
  response.write "your old email address was: " & request.form("email") & "<BR>"
  response.write "your new email address was: " &  request.form("newemail")

%>


HTH...

HAppy programming...

subgenius,

This will meet the requirement that you given above...

save this as confirm.asp

====
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<table width="50%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2">The record for <%= " " & request.form("email") & " "%> has been updated
      to:</td>
  </tr>
  <tr>
    <td width="28%">Email address:</td>
    <td width="72%"><%=request.form("newemail")%>@</td>
  </tr>
  <tr>
    <td width="28%">First Name:</td>
    <td width="72%"><%=& request.form("fname")%>@</td>
  </tr>
  <tr>
    <td width="28%">Last Name:</td>
    <td width="72%"><%=request.form("lname")%>@</td>
  </tr>
</table>
</body>
</html>
===

Below are related links regarding server.transfer

http://www.devguru.com/Technologies/asp/quickref/server_transfer.html

http://www.w3schools.com/asp/met_transfer.asp

The reason why I used server.transfer cause I am submitting the page to itself... and when you submit it to the same page the request collection will be gone if you will use response.redirect so response.transfer is one solution...

HTH...

HAppy programming...

gladxml,
I get the following error with the confirm.asp page added:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/poc/confirm.asp, line 19, column 15

I can't find the problem.  
Should this line
   
<form name="inputform" method="Post" action="email-update.asp" Onsubmit="return validate(this)"><br>

have confirm.asp in it instead of email-update.asp?

confirm.asp, line 19 is this:
   <td width="72%"><%=& request("fname")%> </td>
Thanks.
dmstrat,
Thanks.
I tried what you suggested and it did display what I wanted but it also displays the form input boxes and Submit boxes just as they are seen on the first page.
ASKER CERTIFIED SOLUTION
Avatar of gladxml
gladxml

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
gladxml,
Thanks for all your help.  I'm struggling now with adding a new record.  If I can't get myself unstuck, I'll post a new question under the title "add new record, Oracle"
Thanks again.
subgenius,

Why a grade of B?

KIndly check out the link below on the grading system.

https://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3

To change the grade you can ask a zero point question on the community support
Below is the link.


https://www.experts-exchange.com/Community_Support/

Regards,
gladxml
gladxml,
You are absolutely right.  Your response did meet the criteria of a "thorough answer" and should be graded as an A.  My mistake, I'll request that the grade be changed.  Sorry for the confusion.  Thanks again.
Grade change request by subgenius.  Changed from B to A.

SpideyMod
Community Support Moderator @Experts Exchange