Click to See Complete Forum and Search --> : VBscript and Javascript


vcstarter
October 1st, 2005, 10:39 PM
This form works fine. I can send email through the form, however the javascript and the vbscrip portion doesnot work. I don't know vbscript and javascript. Can someone fix it for me. The vb part format the email and the user first name and lastname while the javascript part display alerts if the fields are blank.


<html>
<head>
<title>The Speak Logic WebSite</title>

</head>

<body style="text-align: left">
<script language = "vbscript" type="text/vbscript">
Dim firstname, lastname, emailaddress

firstname = Request.Form("FirstName ")
lastname = Request.Form("LastName")
emailaddress = Request.Form("Email")
objMessage.Sender = firstname & " " & lastname & "<" & emailaddress & >"
</script>


<span style="font-size: 24pt; color: #0000ff;">Contact Us</span><br>
<form action = "gdform.asp" method="post"> &nbsp;
<strong>First Name:</strong><br>
<input name="FirstName" style="width: 176px" type="text"><br>
<strong>Last Name:</strong><br>
<input name="LastName" style="width: 173px" type="text"><br>
<strong>Email Address:</strong><br>
<input name="Email" style="width: 173px" type="text"><br>
<strong>Subject:</strong><br>
<input name="Subject" style="width: 548px" type="text"><br />
<br>
<strong>Comment:</strong><br>
<textarea name="Comment" style="width: 548px; height: 394px"></textarea><br>
<br>
<input type="submit" value="Submit Form" onclick = "ValidateForm()" style="width: 103px; font-weight: bold;">
&nbsp; &nbsp; &nbsp;<input type="reset" value="Reset" style="font-weight: bold; width: 89px" /><br>
</form>

<script language = "javascript" type="text/javascript">
function ValidateForm()
{
var x;
x = 0
if(info.fn.value==""){
window.alert("Please enter your first name");
x = x + 1;
info.fn.focus();
}
if(info.ln.value==""){
window.alert("Please enter your last name");
x = x + 1;
info.ln.focus();
}
if(info.addr.value==""){
window.alert("Please enter your email address");
x = x + 1;
info.addr.focus();
}
if(info.com.value==""){
window.alert("Please enter your comment name");
x = x + 1;
info.com.focus();
}

if(x==0){document.info.submit()}

}

</script>
</body>
</html>

PeejAvery
October 1st, 2005, 11:03 PM
As to the JavaScript...

1. Don't use spacing with equals signs.
language = "vbscript"
2. Don't forget names on the form.
<form action="gdform.asp" method="post" name="info">
3. Names must coincide for JavaScript to pick them out.
<input name="addr" style="width: 173px" type="text">

Dim firstname, lastname, emailaddress
firstname = Request.Form("fn")
lastname = Request.Form("ln")
emailaddress = Request.Form("addr")
objMessage.Sender = firstname & " " & lastname & "<" & emailaddress & >"

if(info.addr.value==""){
window.alert("Please enter your email address");
x = x + 1;
info.addr.focus();
}

So here is what I have now. I haven't tested the VBScript though.
<html>
<title>The Speak Logic WebSite</title>
<body style="text-align: left">
<script language = "vbscript" type="text/vbscript">
Dim firstname, lastname, emailaddress
firstname = Request.Form("fn")
lastname = Request.Form("ln")
emailaddress = Request.Form("addr")
objMessage.Sender = firstname & " " & lastname & "<" & emailaddress & >"
</script>

<script language="JavaScript" type="text/javascript">
function ValidateForm(){
var x;
x = 0;
if(info.fn.value==""){
window.alert("Please enter your first name");
x = x + 1;
info.fn.focus();
}
if(info.ln.value==""){
window.alert("Please enter your last name");
x = x + 1;
info.ln.focus();
}
if(info.addr.value==""){
window.alert("Please enter your email address");
x = x + 1;
info.addr.focus();
}
if(info.com.value==""){
window.alert("Please enter your comment name");
x = x + 1;
info.com.focus();
}
if(x==0){document.info.submit()}
}
</script>

<span style="font-size: 24pt; color: #0000ff;">Contact Us</span><br>
<form action="gdform.asp" method="post" name="info"> &nbsp;
<strong>First Name:</strong><br>
<input name="fn" style="width: 176px" type="text"><br>
<strong>Last Name:</strong><br>
<input name="ln" style="width: 173px" type="text"><br>
<strong>Email Address:</strong><br>
<input name="addr" style="width: 173px" type="text"><br>
<strong>Subject:</strong><br>
<input name="sub" style="width: 548px" type="text"><br>
<br>
<strong>Comment:</strong><br>
<textarea name="com" style="width: 548px; height: 394px"></textarea><br>
<br>
<input type="button" value="Submit Form" onclick="ValidateForm()" style="width: 103px; font-weight: bold;">
&nbsp&nbsp&nbsp<input type="reset" value="Reset" style="font-weight: bold; width: 89px"><br>
</form>

</body>
</html>

vcstarter
October 1st, 2005, 11:36 PM
Your code may work. The java part works, however the vbpart does not work. There is a problem on this variable

objMessage

it has never been define. It seems like it is an object and I don't know how to define it.

PeejAvery
October 2nd, 2005, 12:00 AM
I haven't tested the VBScript though.
I don't work with VBScript although I do know a chunk of Visual Basic.
it has never been define. It seems like it is an object and I don't know how to define it.
Exactly what is objMessage exactly anyway?

vcstarter
October 2nd, 2005, 12:03 AM
Thank you very much, Iwill find a way to define that object.

vcstarter
October 2nd, 2005, 12:13 AM
Another question, this is an html question. About formating the comment area. For istance currently when I receive a comment, I get it on the form of

comment: fldkf

for istance everything in the same line. If the user add a blank line, I will never receive it. In other words, I receive all the comment in one paragraph, even if the user adds multiple paragraph. So how do I format the comment area to accept multiple paragraphs?

Dr. Script
October 2nd, 2005, 11:02 AM
So you mean if they hit return/enter, you don't receive anythign after that? Use JavaScript to replace the occurences of \n. Change:if(x==0){document.info.submit()}to:if(x==0) {
document.info.comment.value = document.info.comment.value.replace(/\n/g,"***");
document.info.submit();
}That will replace every inbstance of a return with *** right before submitting. Additionally, everytime you check if (info.field.value), reference the document like this:if(document.info.field.value ...)Dr. Script

vcstarter
October 2nd, 2005, 03:54 PM
this line of code does not work. I remove the g, I think it iwas a type. I received an error. Again, I want to be able to receive multiple paragraph. Right now, if someone send me 3 paragraph, I will receive only one. The three paragraphs will be combined to one.

For instance you send me

paragraph 1

paragraph 2

paragraph 3

instead of receive it the way you send it to me above

I will receive

paragraph 1 paragraph 2 paragraph 3

this is the problem I try to solve


if(x==0) {
document.info.comment.value = document.info.comment.value.replace(/\n/g,"***");
document.info.submit();
}

Dr. Script
October 2nd, 2005, 10:00 PM
Oh come on ... just look at the code, and see that my code was generic, and you need to change comment to com. By giving you generic code, I want you to understand it. I won't do everything for you without getting you to learn anything ... chnage comment to com. You should've picked that up on your own though.

vcstarter
October 2nd, 2005, 11:11 PM
I still get an error. It said that 'document.info.com' is null or not an object