0

I have a very simple drop down menu:

<select name="sNumR" id="sNumR" onChange="addTable()">
    <option value=1>1</option>
    <%For i=2 to 10
        Response.write("<option value="&i&">"&i&"</option>")
    Next%>
</select>

All I'm trying to do is access the selected value, whether it be the default value of 1 or otherwise. Please don't list a jQuery or javascript solution as I already know how to do that and am not concerned about that at all.

The simple: Request.Form("sNumR") doesn't work. I've tried it, many times...

What is it I'm missing? Is this even possible with vbscript/asp? I prefer a method that is simple as I believe this task should be but at this point I'm willing to take whatever I can get.

4
  • 1
    Is your <select> wrapped in a <form> and is the form method set to POST? Commented Oct 1, 2014 at 7:33
  • I went ahead and tried some things with the information you provided and I can in fact get the value after submitting the form but I'd like to be able to obtain it before. Is this possible with vbscript/asp? Commented Oct 2, 2014 at 0:07
  • Classic ASP is server side coding so you need a trip to the server before you can access the Request object collections. To gain the value before use client side code such as JavaScript to access the value via the DOM. Something like document.getElementById("sNumR").value; for example. Don't confuse server side code with client side functionality, remember the server knows nothing of your page just what you send to it via form submissions (be it vanilla forms or ajax calls). Commented Oct 2, 2014 at 0:15
  • 1
    I hear ya, thanks again. You're right though, that's kind of my problem; wanting server side scripting to do what client side does... I have a good time doing javascript and then when I need to make everything else work it's like what's asp again? lol anyway sorry for confusing ppl. I did get my site to work though by simply moving my opening form element tag so that it encloses the drop down menu :D Commented Oct 2, 2014 at 1:49

2 Answers 2

1

Request.Form() collection can only be accessed once data has been submitted, you do this either using client-side code to trigger a form submit or using an <input type="submit" />

This whole mechanic relies on the fact that your <select> and <input> tags are wrapped inside a <form> tag. The form has specific attributes you have to set to to access the Request.Form() collection.

  • action - Specifies URL you are submitting the form to, empty string will submit to the current page.

  • method - Either GET (to populate the Request.QueryString() collection) or POST (to populate the Request.Form() collection.

A simple HTML form example would like this;

<html>
  <head>
    <title>Sample Form</title>
  </head>

  <body>
    <form action="" method="post">
      <input type="submit" name="submit" value="Submit Form" />
    </form>
  </body>
</html>

This will do a form POST to the current page (assuming it's called example.asp)

POST /example.asp HTTP/1.1
Host: example.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 20

submit=Submit%20Form

You can then insert ASP anywhere in that page to access the Request.Form() collection for example, placing this code above the HTML in example.asp

<%
Dim is_submit
'Have we submitted the form?
is_submit = (Request.Form("submit") = "Submit Form")

Response.Write "Form submitted: " & is_submit
%>

Will produce Form submitted: False before submission and Form submitted: True after submission.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for your reply. Is there another way of grabbing the value of a drop down option in either asp or vbscript? Basically a way other than request.form? I'm going to need this value prior to the page being submitted. Thanks
0

Try wrapping your value attribute value with double quotes.

<option value="1">1</option>

Other than that, check your variable names.

5 Comments

Although i'd advise that, it doesn't make difference as far as HTML is concerned. Its more likely the OP doesn't understand how forms work with server-side code.
It's either that or they might not even have IIS enabled, never know.
They might not even have a keyboard, you never know.
That's the whole problem with these types of questions, you find yourself constantly trying to second guess the OP.
You're correct in that I don't fully understand how forms work but I have a general idea and am learning more. That being said, is there another way to access the drop-down-menu's option value other than using Request.Form()? I need the selected drop down value for part of an sql loop I've created.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.