Server Side Javascript option Select Problem

Discussion in 'Javascript' started by Eric Tuomikoski, Jun 5, 2004.

  1. Im having trouble with server side ASP with Javascript.
    I have an ADO recordset that returns a list of Times example: 7:00AM. I
    then populate the option box with the results. (see below) The problem
    is I have a variable called Item_Start, that contains a time that is
    determined from another procedure. I simply wish to auto select the
    option if it is found. This all happens when the page loads.
    You can see below I tried, but it failed. How do I do this with
    Javascript? Im not very good with Java at all..so please correct. Say
    that item_start = 1:00AM and there IS a 1:00AM in one of the recordset
    items ADO_RS("Times"). I simply wish to have the 1:00AM selected in the
    dropdown when the page loads.

    <%while (!ADO_RS.EOF)
    { %>
    <option VALUE ="<%if (item_start == ADO_RS("Times"))
    Response.Write(" selected
    ");%><%=ADO_RS("Times")%>"><%=ADO_RS("Times")%></option>
    <% ADO_RS.movenext();}
    ADO_RS.Close(); %>

    thanks all !
    Eric Tuomikoski

    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Eric Tuomikoski, Jun 5, 2004
    #1
    1. Advertising

  2. Eric Tuomikoski wrote:
    > Im having trouble with server side ASP with Javascript.
    > I have an ADO recordset that returns a list of Times example: 7:00AM.
    > I then populate the option box with the results. (see below) The
    > problem is I have a variable called Item_Start, that contains a time
    > that is determined from another procedure. I simply wish to auto
    > select the option if it is found. This all happens when the page
    > loads.


    You have a conceptual problem here. The page "loads" into a browser. The
    ASP creates the HTML contents of an HTTP response first, that response
    is then sent to the browser, at which point it loads, by which time your
    server-side script is long finished.

    > You can see below I tried, but it failed. How do I do this with
    > Javascript? Im not very good with Java at all..so please correct.


    OK. Java and javascript are distinct programming languages that share
    nothing but some characters in their names and syntax that is
    reminiscent of C in both cases.

    > Say that item_start = 1:00AM and
    > there IS a 1:00AM in one of the recordset
    > items ADO_RS("Times"). I simply wish to have the 1:00AM
    > selected in the dropdown when the page loads.


    ASP generates HTML (mostly) and sends that HTML to a browser (or maybe
    other client). Much of the time problems with server-side scripts can be
    diagnosed by viewing the HTML they generate using a view-source facility
    in the browser, and doing so in this case probably would have indicated
    the problem.

    > <%while (!ADO_RS.EOF)
    > { %>
    > <option VALUE ="


    Output value attribute, equals sign and opening quote.

    ><%if (item_start == ADO_RS("Times")) Response.Write(" selected");%>


    If the - item_start - variable (string?) equals the value returnd from -
    ADO_RS("Times") - output a space and the word 'selected'.

    ><%=ADO_RS("Times")%>">


    output the string returned from a call to - ADO_RS("Times") - followed
    by another double quote and '>'.

    At this point, if - item_start - equalled '1:00AM' and -
    ADO_RS("Times") - returned '1:00AM' the HTML for the opening OPTION tag
    looks like:-

    <option VALUE =" selected1:00AM">

    And that is valid, but not at all what you wanted. Move the ASP
    expression tag that outputs ' selected' to after the double quote that
    ends the VALUE attribute.

    Get used to viewing the source in the browser while writing ASP and you
    will be able to see when what your output is not what you intended to
    output.

    Richard.
    Richard Cornford, Jun 5, 2004
    #2
    1. Advertising

  3. Perfect. Thanks Richard.

    Eric Tuomikoski

    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Eric Tuomikoski, Jun 5, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Azmarae
    Replies:
    1
    Views:
    534
    Carlos Campos
    Mar 3, 2004
  2. J. Hall
    Replies:
    2
    Views:
    1,045
    Jeff Thies
    Apr 21, 2004
  3. WebRaster
    Replies:
    1
    Views:
    260
    Francisco Spaeth
    Oct 26, 2005
  4. Nick Spacek

    Removing select option removes entire select

    Nick Spacek, Jun 21, 2006, in forum: Javascript
    Replies:
    1
    Views:
    141
    Matt Kruse
    Jun 21, 2006
  5. rvelosoo
    Replies:
    1
    Views:
    319
    Bart Van der Donck
    Aug 13, 2008
Loading...

Share This Page