PDA

Click to See Complete Forum and Search --> : Probably really obvious but...


Bigley
Oct 2nd, 2000, 09:03 AM
Why when I try the following
<script language="VBSCRIPT">
fname = request.form("FirstName")
msgbox(fname)
</Script

Do I get the error

Object required :'request'

But if I just use the <% %> tags it works ok.

And vica versa with msgbox except the error message is permission denied:'Msgbox'

Bigley
Oct 2nd, 2000, 09:50 AM
Ok so it is obvious then <% is ASP whilst VBSCRIPT is VB script ..duh!

But how can I access the values in my request.form inside the VB script?

monte96
Oct 2nd, 2000, 10:27 AM
Actually it's the separation of Client side script from Server side script.

Request object is only available on the server side.

The best way to do validation of your form data is BEFORE it is submitted. You should never use MsgBox except for debugging in ASP cuz it only work on the server and typically there is nobody at the server to click OK and it will cause the server to appear to hang (cuz it's waiting for someone to click on the modal Msgbox window).

BTW for client side script:
window.alert = msgbox

Try this:


<HTML>
<HEAD>
<SCRIPT language="VBScript">
'This is the same as LostFocus
Sub FirstName_onblur
Dim fname
fname = frmMyForm.FirstName.value
window.alert fname
End Sub
</SCRIPT>
</HEAD>
<BODY>
<FORM id=frmMyForm action="MyPage.asp" method=post>
<INPUT type=Text id=FirstName>
</FORM>
</BODY>
</HTML>

Bigley
Oct 2nd, 2000, 04:20 PM
Thanks for the explanation Monte.
The message box wasn't really my goal here.
I have validated my data on a form and passed it to an ASP and on this ASP I want to get all the request.form stuff into one big long string and then e-mail it to myself using jmail. The exmaples of JMail I have seen seem to indicate that it will work inside server side tags (<% %>) but I have found that this is not the case and infact it only works inside vbScript tags. The problem then is that my request.form only works inside the ASP tags and if I try to set a variable to the value of request.form info, it is reinitialised inside the vbscript tags and all the info is gone.
So how can I pass the info from the ASP script to the VB script?

Thanks again

monte96
Oct 2nd, 2000, 05:35 PM
You will need to use the server side script and Response.Write to create dynamic client side script

For example:


<HTML>
<HEAD>
<SCRIPT language="VBScript">
<!--
<%
Response.Write "Dim strMyValue" & vbCrLf
Response.Write "strMyValue = " & Request.Form("SomeFormData") & vbCrLf
%>
'Then you can use the variable strMyValue in your client side scripts
-->
</SCRIPT>
</HEAD>
.
.
.


You are essentially passing the server side only info to the page by putting it in the HTML stream on page itself.

Bigley
Oct 3rd, 2000, 02:53 AM
I see what you are saying here Monte and it makes good sense but I am having a slight problem running it. Now I am working on it myself but incase it is more obvious to you perhaps you could help me.....

<html>

<head>
<title>Confirmation_Page</title>
<script language="VBScript">
<!--
<%
Response.Write "Dim FName" & vbCrLf
Response.Write "FName = " & Request.Form("FirstName") & vbCrLf
%>
-->
</script>
</head>

I am getting an error on line 7 - the first ASP tag : 'Expected statement'. Thanks again and if you ever need SQL and VB6 help let me know.

monte96
Oct 3rd, 2000, 10:29 AM
Assuming your using the same page to get the info from the text box, you will need to do something like this to handle when there is no form data (i.e. when the page is loaded from something other than a submit action)


<html>

<head>
<title>Confirmation_Page</title>
<script language="VBScript">
<!--
<%
Response.Write "Dim FName" & vbCrLf
If len(Request.Form("FirstName")) > 0 Then
Response.Write "FName = " & Request.Form("FirstName") & vbCrLf
Else
Response.Write "FName = " & CHR(34) & CHR(34) & vbCrLf
End If
%>
-->
</script>
</head>



That will handle when the form data is blank. If you set on error resume next inside the script tag and then view source on the page when it loads, you will see why it's complaining. You end up with


<script language="VBScript">
<!--
Dim FName
FName =
-->
</script>
</head>


Now, if your using a different page to process the form data than the one you are gathering it on, then you need to make sure that the method attribute in your form is set to post:


<FORM id=myformname action="processpage.asp" method=post>


otherwise you are passing a querystring to the page instead of form data. You could alternately handle that by using the request object like this:


Request("FirstName")


While this seems like a fix, it is a bit slower cuz the server has to search through the collections in a specific order to locate your "FirstName" key. When it's so easy to be explicit, why not be.

Bigley
Oct 3rd, 2000, 04:16 PM
Monte, thanks again.
We are obviously many timezones apart here because I have had a full days working on this and I finally came up with a solution (with the information you had given me) to my problem. It's probably a bit of a hack, but I set up a string and make it equal to all the values that I pass to my asp using the request.form("fieldname") function. I then initialize a text object to that string's value. Then inside my Vbscript I can just refer to the value of that text object. I set the text object to be too small to be visible on the form and voila - hack complete.

Thanks again for all the help, I couldn't have done it without you.

monte96
Oct 3rd, 2000, 07:26 PM
Instead of using a text object (Assume you mean an INPUT tag), set the type="hidden". Then you don't have to worry about it's size and you can access it the same way.

Bigley
Oct 4th, 2000, 02:19 AM
I did have the idea of using the hidden object, but for whatever reason it did not seem to like me assigning it a variable value in asp tags, so that is why I went the way of the text box. But now that I have a functional version ( enought to keep my bosses quiet) I might look a little closer at the hidden input object.

Nice one

Bigley