Link to home
Start Free TrialLog in
Avatar of thatcoolguyAK
thatcoolguyAK

asked on

VBScript form variables

Scenario:

I have a form with 5 fields. When I click on a button, I need a VBScript that stores all the values in the form fields in respective variables. I need to use these variables in a procedure.

How can I set variables to the form field values??
Avatar of CoolAss
CoolAss

make the action of your form:

ACTION="process.asp" METHOD="POST"

Now this is the process.asp

Var1 = Request.Form("inputname1")
Var2 = Request.Form("inputname2")
Var3 = Request.Form("inputname3")
Var4 = Request.Form("inputname4")
Var5 = Request.Form("inputname5")

Now call your procedure with those variables. This assumes that your page with the form has the text boxes named inputname1, etc...

Avatar of thatcoolguyAK

ASKER

Adjusted points from 20 to 30
I dont want to post the variables to another form. I'd rather use an event that looks at all the fields of the page and picks up their values
I dont want to post the variables to another form. I'd rather use an event that looks at all the fields of the page and picks up their values
Use the onclick event.

You have a form with a name. And all the option / input boxes etc. have a name too. Then when the user clicks a button you do

<input type=button onclick="javascript:IsClicked()">

The javascript function will look like:

function IsClicked()
{
        value1=formname.formitem.value;
        ...
        return false;
}

Only use return false if you don't want the page to reload.


I need it to be VEEE BEEEE Script mate.
Not JavaScript
Oh.VEEEEEEBEEEEEEE =)

Mate, here ya go...this should help you

<HTML>
<HEAD><TITLE>Simple Validation</TITLE>
<SCRIPT LANGUAGE="VBScript">
<!--
Sub Button1_OnClick
  Dim TheForm
  Set TheForm = Document.ValidForm
  If IsNumeric(TheForm.Text1.Value) Then
    If TheForm.Text1.Value < 1 Or TheForm.Text1.Value > 10 Then
      MsgBox "Please enter a number between 1 and 10."
    Else
      MsgBox "Thank you."
    End If
  Else
    MsgBox "Please enter a numeric value."
  End If
End Sub
-->
</SCRIPT>
</HEAD>
<BODY>
<H3>Simple Validation</H3><HR>
<FORM NAME="ValidForm">
Enter a value between 1 and 10:
<INPUT NAME="Text1" TYPE="TEXT" SIZE="2">
<INPUT NAME="Button1" TYPE="BUTTON" VALUE="Submit">
</FORM>
</BODY>
</HTML>

ASKER CERTIFIED SOLUTION
Avatar of CJ_S
CJ_S
Flag of Netherlands image

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