Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Form Select - out of order....

Reply
Thread Tools

Form Select - out of order....

 
 
david@scene-double.co.uk
Guest
Posts: n/a
 
      02-02-2005
Hi,

I have a form with 2 select objects which are not linked together in
any way. The list exactly the same information.

The code that generates the data is:

_________________________________________

<SCRIPT language='vbscript'>
Sub Window_Onload
Dim TheDate
Dim Count
Dim Options
Dim Options2


TheDate2 = Date + vbThursday - WeekDay(Date)
TheDate = Date + vbTuesday - WeekDay(Date)


If TheDate < Date Then TheDate = TheDate +7
Set Options = Document.all.date.Options
Set Options2 = Document.all.todate.Options

For Count = 1 To 20-1
StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
Right("0" & Month(TheDate),2) & "/" & Year(TheDate)
Options.Add Window.Option(StrDate,"from " & StrDate)
Options2.Add Window.Option(StrDate,"to " & StrDate)
TheDate = TheDate + 7

StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" &
Right("0" & Month(TheDate2),2) & "/" & Year(TheDate2)
Options.Add Window.Option(StrDate2,"from " & StrDate2)
Options2.Add Window.Option(StrDate2,"to " & StrDate2)
TheDate2 = TheDate2 + 7
Next
End Sub

</script>

______________________________________________

The information is correct, except that every now and again the Tusdays
& Thursdays are wrong way around depending on the current date, i.e.

it should display:

Thursday 03/02/2005
Tuesday 08/02/2005

looping continuously with Tuesdays & Thursdays in the correct date
order.

I seem to get

Tuesday 08/02/2005
Thursday 03/02/2005

How can I correct this code so that no matter what the actual date is,
the data is always in the correct order ?
Appreciate your advice



David.

 
Reply With Quote
 
 
 
 
Lee
Guest
Posts: n/a
 
      02-02-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) said:
>
>Hi,
>
>I have a form with 2 select objects which are not linked together in
>any way. The list exactly the same information.
>
>The code that generates the data is:
>
>_________________________________________
>
><SCRIPT language='vbscript'>


>How can I correct this code so that no matter what the actual date is,
>the data is always in the correct order ?
>Appreciate your advice


My advice is to ask in a vbscript group, rather than javascript.
Sorry.

 
Reply With Quote
 
 
 
 
Dr John Stockton
Guest
Posts: n/a
 
      02-03-2005
JRS: In article <(E-Mail Removed). com>,
dated Wed, 2 Feb 2005 08:03:35, seen in news:comp.lang.javascript,
(E-Mail Removed) posted :

>I have a form with 2 select objects which are not linked together in
>any way.
> The list exactly the same information.


Meaning absent.

>The code that generates the data is:
>
>_________________________________________
>
><SCRIPT language='vbscript'>


Doubly deprecated. Should be <script type="text/javascript"> here

>Sub Window_Onload
>Dim TheDate
>Dim Count
>Dim Options
>Dim Options2
>
>
>TheDate2 = Date + vbThursday - WeekDay(Date)
>TheDate = Date + vbTuesday - WeekDay(Date)
>
>
>If TheDate < Date Then TheDate = TheDate +7
>Set Options = Document.all.date.Options
>Set Options2 = Document.all.todate.Options
>
>For Count = 1 To 20-1
>StrDate = "Tuesday " & Right("0" & Day(TheDate),2) & "/" &
>Right("0" & Month(TheDate),2) & "/" & Year(TheDate)
>Options.Add Window.Option(StrDate,"from " & StrDate)
>Options2.Add Window.Option(StrDate,"to " & StrDate)
>TheDate = TheDate + 7
>
>StrDate2 = "Thursday " & Right("0" & Day(TheDate2),2) & "/" &
>Right("0" & Month(TheDate2),2) & "/" & Year(TheDate2)
>Options.Add Window.Option(StrDate2,"from " & StrDate2)
>Options2.Add Window.Option(StrDate2,"to " & StrDate2)
>TheDate2 = TheDate2 + 7
>Next
>End Sub
>
></script>
>
>______________________________________________
>
>The information is correct, except that every now and again the Tusdays
>& Thursdays are wrong way around depending on the current date, i.e.
>
>it should display:
>
>Thursday 03/02/2005
>Tuesday 08/02/2005
>
>looping continuously with Tuesdays & Thursdays in the correct date
>order.
>
>I seem to get
>
>Tuesday 08/02/2005
>Thursday 03/02/2005
>
>How can I correct this code so that no matter what the actual date is,
>the data is always in the correct order ?
>Appreciate your advice



Code should be written and posted with indentation to show the intended
structure.

Lines should not be allowed to be broken by the posting agent; you
should present us with code that can be read and tested directly, with
only the original faults.


For Right("0" & Day(TheDate2),2)
Right(100+Day(TheDate2),2) ' is better, at least for me

Date should be called only once; it is comparatively expensive, and can
change.

TheDate2 is not declared.

Variable names should be short or meaningful, or both.

My system does not believe document.all.date .

You seem to be saying that the first two dates (among others) are in the
wrong order. So don't bother us with the loop.

The following "Web page" suffices to show us what is needed to be shown
:-


<SCRIPT language='vbscript'>

Dim TheDate, TheDate2

TheDate2 = Date + vbThursday - WeekDay(Date)
TheDate = Date + vbTuesday - WeekDay(Date)

If TheDate < Date Then TheDate = TheDate +7

document.write TheDate, " ", TheDate2

</script>


The following transform is more illustrative :-


<SCRIPT language='vbscript'>

Dim Tue, Thu, Dt

Dt = Date
for J = 0 to 15
D = Dt + J
Thu = D + vbThursday - WeekDay(D)
Tue = D + vbTuesday - WeekDay(D)

If Tue < D Then Tue = Tue +7 ' ###

document.write D, " - ", Thu, " - ", Tue, "<br>"
next
</script>

and the line marked ### looks implausible;
if Tue < Thu makes more sense



Now


<SCRIPT language='vbscript'>

Dim Tue, Thu, Dt, SoW

Dt = Date
for J = 0 to 15
D = Dt + J

SoW = D - WeekDay(D)
Thu = SoW + vbThursday
Tue = SoW + vbTuesday
If Tue < Thu Then Tue = Tue +7

document.write D, " - ", Thu, " - ", Tue, "<br>"
next
</script>

gives me

2005-02-03 - 2005-02-03 - 2005-02-08
2005-02-04 - 2005-02-03 - 2005-02-08
2005-02-05 - 2005-02-03 - 2005-02-08
2005-02-06 - 2005-02-10 - 2005-02-15
2005-02-07 - 2005-02-10 - 2005-02-15
2005-02-08 - 2005-02-10 - 2005-02-15
2005-02-09 - 2005-02-10 - 2005-02-15
2005-02-10 - 2005-02-10 - 2005-02-15
2005-02-11 - 2005-02-10 - 2005-02-15
2005-02-12 - 2005-02-10 - 2005-02-15
2005-02-13 - 2005-02-17 - 2005-02-22
2005-02-14 - 2005-02-17 - 2005-02-22
2005-02-15 - 2005-02-17 - 2005-02-22
2005-02-16 - 2005-02-17 - 2005-02-22
2005-02-17 - 2005-02-17 - 2005-02-22
2005-02-18 - 2005-02-17 - 2005-02-22



You need to learn how to test misbehaving code - always simplify it,
testing continually, until the solution is obvious (always keep the last
failing version). Then, with the new understanding, the original can
probably be fixed.

--
John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 IE 4
<URL:http://www.jibbering.com/faq/> JL/RC: FAQ of news:comp.lang.javascript
<URL:http://www.merlyn.demon.co.uk/js-index.htm> jscr maths, dates, sources.
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/jscr/&c, FAQ items, links.
 
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
select() call and filedescriptor out of range in select error k3xji Python 5 09-16-2010 07:14 AM
"//form[...]//input | //form[...]//select" or can I combine them? yawnmoth XML 2 08-18-2008 09:04 PM
Refresh "parent" form after filling out child popUp form? Bob ASP .Net 1 08-31-2007 09:39 AM
Refresh "parent" form after filling out child popUp form? Bob ASP .Net 0 08-31-2007 09:06 AM
select of select box will select multiple in another box palmiere Javascript 1 02-09-2004 01:11 PM



Advertisments