Server Side Javascript option Select Problem

  • Thread starter Eric Tuomikoski
  • Start date
E

Eric Tuomikoski

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!
 
R

Richard Cornford

Eric said:
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.
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top