Type mismatch problems with select box list

Discussion in 'ASP General' started by .Net Sports, Dec 21, 2009.

  1. .Net Sports

    .Net Sports Guest

    I have an item that goes into sql database coming from a select
    pulldown list.:

    <br>ACCESS LEVEL:<br> <select name=level><option value= SELECTED>"&
    RSFORM("level")&"</option><option value=1>1</option><option value=2>2</
    option></select>

    Level is an integer datatype in the dbase, and is either a numeral 1,
    2 ,or 3

    when trying to either update or insert into the dbase:

    RSEVENTS("level") = cint(request("level"))

    I get a vbscript Type mismatch: 'cint' on this line; get the same
    error no matter if i leave the function blank " request("level")

    ??
    NS
     
    .Net Sports, Dec 21, 2009
    #1
    1. Advertisements

  2. .Net Sports

    Bob Barrows Guest

    Show us the result of

    Response.Write request("level")
     
    Bob Barrows, Dec 21, 2009
    #2
    1. Advertisements

  3. .Net Sports

    Evertjan. Guest

    Bob Barrows wrote on 21 dec 2009 in
    microsoft.public.inetserver.asp.general:

    What is "leaving the function blank?
    What is "blank", an empty string?

    Do you mean the argument of cint() ?

    Cint() errors out if the argument is not convertable to a number,
    so an empty string will give an error.

    This will possibly not help you, Bob,
    as you cannot see the difference between
    "1" and +1.

    ====================

    and never never use request("level")

    specify what type of request you want to read, like:

    request.cookies("level")

    request.form("level")

    request.querystring("level")

    Request.servervariables("..")

    or other.
     
    Evertjan., Dec 21, 2009
    #3
  4. .Net Sports

    Bob Barrows Guest

    Are you sure? Did you look at his source?
     
    Bob Barrows, Dec 21, 2009
    #4
  5. .Net Sports

    .Net Sports Guest

    If i don't need to change the Level when editing the record, then i
    want to leave what their existing level number is in the first line of
    the select option box: <select name=level><option value= SELECTED>"&
    RSFORM("level")&"</option><option value=1>1</option><option
    value=2>2</
    option></select>

    I tried response.writing the request("level") on the next page, and it
    is blank , so something is not coming across in the post right:

    <form action="resources-edit-post.asp?qencl=admin" name="frmUser"
    Method="Post">
    ''' content
    </form>
     
    .Net Sports, Dec 22, 2009
    #5
  6. .Net Sports

    Bob Barrows Guest


    Look at the value attributes of each of your option elements ... which one
    is selected when you submit the form? What is the value of that selected
    option?
     
    Bob Barrows, Dec 22, 2009
    #6
  7. You've got a few bad things going on here.

    1. You really should quote all your HTML attributes. It makes debugging
    a lot easier.
    2. What is the value of the option? You have a blank value, you really
    do, and had you quoted attribute values correctly you would have seen
    that. Look at the source of the document when it has been rendered in a
    browser and you will see what I mean. This is the correct method:

    <option value="<%=rsform("level")%>" selected><%=rsform("level")%>
    </option>

    3. Are you looping through the records - from your naming conventions it
    appears you are, so why would you have ALL options selected? You have
    to put some appropriate if statements in there.

    4. It's not a good idea to use request("level") - because you are not
    explicitly telling the server to look for a post value. You should
    always use request.form("field") for post method, or request.querystring
    ("field") for get method, or request.cookies("field") for cookies, or
    request.servervariables("field").

    I got into trouble a long time ago, before someone here showed me the
    error of my ways, where I had an input that was called url, and when I
    did request("url") it was giving me the url of the page, not information
    the user had posted in the form. IIRC server variables are read first.

    5. Using the name attribute of the form element is deprecated. You
    would do better to use the id attribute, especially if you are going to
    be using client side scripting for modern browsers.
     
    Adrienne Boswell, Dec 22, 2009
    #7
  8. .Net Sports

    Dan Guest

    There's your problem, right there, at the value=. Where's the value? For
    example, is RSFORM("level") is the value 1, the HTML becomes

    <select name=level><option value= SELECTED>1</option>

    so if the user picks 1 from the list (which is pre-selected so is highly
    likely), the value is blank because you have not provided the value. The
    change for this line should be something like

    <br>ACCESS LEVEL:<br> <select name=level><option value=" & RSFORM("level") &
    " SELECTED>" & RSFORM("level") & "</option>
     
    Dan, Dec 22, 2009
    #8
  9. .Net Sports

    Evertjan. Guest

    Bob Barrows wrote on 22 dec 2009 in
    microsoft.public.inetserver.asp.general:
    Possibly I was,

    .... but not now, as both will be accepted by cint()
     
    Evertjan., Dec 22, 2009
    #9
  10. .Net Sports

    Bob Barrows Guest

    I guess you're missing the point. If the form above is submitted with
    the default selection,
    request("level")
    , or, more correctly (as you pointed out):
    request.form("level")
    , will return an empty string, in which case cint("") will raise a type
    mismatch error.
     
    Bob Barrows, Dec 22, 2009
    #10
  11. .Net Sports

    .Net Sports Guest


    Thanks! the main culprit was not having the current value for the
    record in the value tag: <option value="& RSFORM("level")&"
    SELECTED>"............
     
    .Net Sports, Dec 22, 2009
    #11
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.