PDA

View Full Version : VBscript and ASP form question


pkarovsky
10-19-2005, 01:54 AM
In my HTML form I have the line
<form action="stepmail.asp" method="post" name="regform" id="regform" onsubmit="return checkCheckBox(this)">

The file stepmail.asp contains VBscript. It displays on screen what the user has entered as well as sending the variable contents to a secure mailbox. I'm new at this so I used a series of inelegant VBscript statements. For example
emailText = emailText & Name " & request.form("name") & vbCRLF

I'd like to have an in-between-step but don't know how to do it. I'd like the user to be able to review his/her entries then return to the form to correct them if necessary before submitting the form. I've tried to do this but when I go back and then submit, I lose the variables' values.

Any suggestions?

Deanoo
10-19-2005, 08:37 AM
pkarovsky,

You will need to have a seperate vbscript statement to show the detail to the user. You then pass the same information on to the existing stepmail.asp page for processing. Can you e-mail the code to me and I will have a look for you.
:thumbsup:

glenngv
10-19-2005, 08:56 AM
You can put a [Preview] button beside the [Send] button. What the preview does is submit the page into another page in a new window to display the entered data as uneditable.
function setFormAttrib(oForm, action, target){
oForm.target = target;
oForm.action = action;
if (target=="_popup"){
oForm.onsubmit = function(){
return checkCheckBox(this) && createPopup(target);
}
}
else{
oForm.onsubmit = function(){
return checkCheckBox(this);
}
}
}

function createPopup(target){
var win = window.open("", target, "resizable=1, scrollbars=1, width=600, height=700");
w.focus();
return true;
}
...
<form action="sendmail.asp" method="post" target="_self" onsubmit="return checkCheckBox(this)">
...fields here...
<input type="submit" name="btnSend" value="Send" onclick="setFormAttrib(this.form, 'sendmail.asp', '_self');" />
<input type="submit" name="btnPreview" value="Preview" onclick="setFormAttrib(this.form, 'previewmail.asp', '_popup');" />

pkarovsky
10-19-2005, 06:12 PM
I'm going to try glenngv's preview option. Thank you both for responding to my question.

pkarovsky
10-19-2005, 11:02 PM
I had a function to validate the form as follows:
onClick="MM_validateForm('name','','R','address1','','R','city','','R','State','','R','zip','','NisNum','clas s1','','R','Item1course','','RisNum','card1','','RisNum','card2','','RisNum','card3','','RisNum','ca rd4','','RisNum','datem','','RisNum','datey','','RisNum','totpaid','','RisNum');return document.MM_returnValue" value="Submit form"

now I'm using the script that glenngv sent me (that WORKS)

onclick="setFormAttrib(this.form, 'sendmail.asp', '_self');" />

BUT I don't know how to include the validate function as well with the submit button.

pkarovsky
10-19-2005, 11:59 PM
Sorry folks -- I did a search in the Javascript forum and found my answer.

pkarovsky
10-21-2005, 11:44 PM
When I press either PREVIEW or SUBMIT I get an error message that
Line 12
Character 9
Object Expected

Here is the code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Step into Art</title>
<script language="JavaScript">
<!--
function setFormAttrib(oForm, action, target){
oForm.target = target;
oForm.action = action;
if (target=="_popup"){
oForm.onsubmit = function(){
return checkCheckBox(this) && createPopup(target);
}
}
else{
oForm.onsubmit = function(){
return checkCheckBox(this);
}
}
}

function createPopup(target){
var win = window.open("", target, "resizable=1, scrollbars=1, width=600, height=700");
w.focus();
return true;
}
function noenter() {
return !(window.event && window.event.keyCode == 13); }

function placeFocus() {
if (document.forms.length > 0) {
var field = document.forms[0];
for (i = 0; i < field.length; i++) {
if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type.toString().charAt(0) == "s")) {
document.forms[0].elements[i].focus();
break;
}
}
}



//declare variables
var i, coursetotal, nitems;


function Total() {
coursetotal = 0;
nitems = 3;
for (i=1; i<nitems+1; i++) {
eval("document.regform.Item" + i + "Total.value = '';");
eval("total=document.regform.Item" + i + "course.value * 1;");
eval("document.regform.Item" + i + "Total.value=Currency(total)");
eval("coursetotal = coursetotal + total;");
}
document.regform.coursetotal.value = Currency(coursetotal);
}
function Currency(anynum) {
anynum = "" + eval(anynum) //evaluate (in case an expression sent)
intnum = parseInt(anynum) //isolate integer portion
intnum = Math.abs(intnum)
intstr = ""+intnum
//add comma in thousands place.
if (intnum >= 1000) {
intlen = intstr.length
temp1=parseInt(""+(intnum/1000))
temp2=intstr.substring(intlen-3,intlen)
intstr = temp1+","+temp2
}
decnum = Math.abs(parseFloat(anynum)-parseInt(anynum)) //isolate decimal portion
decnum = decnum * 100 // multiply decimal portion by 100.
decstr = "" + Math.abs(Math.round(decnum))
if (decstr.length>2) {decstr=decstr.substring(0,2)}
while (decstr.length < 2) {decstr="0"+decstr}
retval = intstr + "." + decstr
if (anynum < 0) {
retval="("+retval+")"
}
return "$"+retval
}

function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
}
-->
</script>
.......

then in the body

<td height="30" align="center" ><input name="btnPreview" type="submit" class="descrip_bold" onclick="setFormAttrib(this.form, 'previewmail.asp', '_popup');" value="Preview" /></td>

<td height="30" align="center" descrip>&nbsp;</td>
<td height="30" align="center" descrip>&nbsp;</td>
<td > <input name="btnSend" type="submit" class="name" onclick="setFormAttrib(this.form, 'stepmail.asp', '_self');" value="Send" /> </td> </tr>

glenngv
10-25-2005, 06:01 AM
"Object expected" error means it cannot find the function called. You may have misspelled the function call or the case is different. Try running the page in Firefox to get more detailed error. IE error notification in some cases such as this, produces vague error descriptions and wrong line number. It's easier to debug in Firefox as it exactly points to the erroneous line.

And you don't need to use eval. This:

eval("document.regform.Item" + i + "Total.value = '';");

can be easily done using square bracket notation.

document.regform.elements["Item" + i + "Total"].value = '';

See my sig for more info on this technique.