Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Server Side Javascript option Select Problem

Reply
Thread Tools

Server Side Javascript option Select Problem

 
 
Eric Tuomikoski
Guest
Posts: n/a
 
      06-05-2004
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!
 
Reply With Quote
 
 
 
 
Richard Cornford
Guest
Posts: n/a
 
      06-05-2004
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.


 
Reply With Quote
 
 
 
 
Eric Tuomikoski
Guest
Posts: n/a
 
      06-05-2004
Perfect. Thanks Richard.

Eric Tuomikoski

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

Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Removing select option removes entire select Nick Spacek Javascript 1 06-21-2006 04:45 PM
Client-Side JavaScript Problem in runat=server "<SELECT>" =?Utf-8?B?QWxleCBNYWdoZW4=?= ASP .Net 7 05-01-2006 12:11 PM
modify the default option in a select changing another select WebRaster Javascript 1 10-26-2005 10:36 AM
Selection from One SELECT changes selected option of another SELECT? J. Hall HTML 2 04-21-2004 05:36 PM
Reading Select control from server side which was modified on the client side Azmarae ASP .Net 1 03-03-2004 08:06 PM



Advertisments