Connecting Tech Pros Worldwide Help | Site Map

Server Side Javascript option Select Problem

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 23rd, 2005, 11:24 AM
Eric Tuomikoski
Guest
 
Posts: n/a
Default 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!

  #2  
Old July 23rd, 2005, 11:24 AM
Richard Cornford
Guest
 
Posts: n/a
Default 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("Times")%>">[/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.


  #3  
Old July 23rd, 2005, 11:24 AM
Eric Tuomikoski
Guest
 
Posts: n/a
Default 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!
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.