Server Side Javascript option Select Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Eric Tuomikoski

    Server Side Javascript option Select Problem

    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!
  • Richard Cornford

    #2
    Re: Server Side Javascript option Select Problem

    Eric Tuomikoski wrote:[color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > 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.[/color]

    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.
    [color=blue]
    > <%while (!ADO_RS.EOF)
    > { %>
    > <option VALUE ="[/color]

    Output value attribute, equals sign and opening quote.
    [color=blue]
    ><%if (item_start == ADO_RS("Times") ) Response.Write( " selected");%>[/color]

    If the - item_start - variable (string?) equals the value returnd from -
    ADO_RS("Times") - output a space and the word 'selected'.
    [color=blue]
    ><%=ADO_RS("Tim es")%>">[/color]

    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.


    Comment

    • Eric Tuomikoski

      #3
      Re: Server Side Javascript option Select Problem

      Perfect. Thanks Richard.

      Eric Tuomikoski

      *** Sent via Devdex http://www.devdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...