Results 1 to 10 of 10

Thread: Probably really obvious but...

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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'

  2. #2

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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?

  3. #3
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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:

    Code:
    <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>
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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

  5. #5
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    You will need to use the server side script and Response.Write to create dynamic client side script

    For example:

    Code:
    <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.
    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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.

  7. #7
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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)

    Code:
    <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

    Code:
    <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:

    Code:
    <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:

    Code:
    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.

    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  8. #8

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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.

  9. #9
    Frenzied Member monte96's Avatar
    Join Date
    Sep 2000
    Location
    Somewhere in AZ
    Posts
    1,379
    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.



    oOOo--oOOo
    __/\/\onte96
    oOOo--oOOo
    Senior Programmer/Analyst
    MCP
    [email protected]
    [email protected]


    Your results may vary.. some restrictions may apply.. pricing and participation may vary.. not available in all states.. professional driver closed course..quantities limited..

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2000
    Posts
    284
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width