Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Comparing .value string of combobox w/ JavaScript

Status
Not open for further replies.

4waystop

Programmer
Aug 30, 2004
19
GB
Hi

I've got a form which calls an asp page with POST. Within this form I have a selection box which has a two different options, each identified by a short string - in this case either cc or ca. When I come to call the value of this using:

var payMet = Request.Form("payMethod");

it is not returning just the string. It is likely its returning the selection box "payMethod". This means that when I try to do a comparison in JavaScript to see if the strings are alike:

if(payMet=="cc")...

I always get false. Is there any way around this? payMet.value or .text doesn't seem to work.

Many thanks!
 
Code:
var payMet = Request.Form("payMethod").Item(1);

Request.Form("payMethod") is actually an item in a collection, it is a name/value pair.

Request.Form("payMethod").Item(1) is the value of the first pair. You might think the first one would be Item(0) but remember that Request is a Microsoft concept, the index begins at 1.

Equivalent nottations for the value are
Request.Form("payMethod")(1)
Request.Form("payMethod")()

There is probably a member of the Form object that tells how many items were provided in the POST data, but I dont have it in my notes. Maybe Request.Form("payMethod").Count
or Request.Form("payMethod").Count().
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top