Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

New to programming need help issues 1

Status
Not open for further replies.

Sammy145

Programmer
Oct 4, 2002
173
GB
1.i have this code now all i want is to populate the first listbox with dates.Now i have source code which is date i
can convert this as done below[10/07/02 11 dd/mm/yy hh] but am having problems with LOOP to increment the hour 168 times[7*24=168]
So each our is populated in the first listbox

2. I have javascript to move items from listbox 1 to 2 now all i need to do is get all the items selected in LIST 2 and insert into SQl server Employee table just ID
How do i get all the items in LISTBOX2

<HTML>
<HEAD>
<SCRIPT LANGUAGE=&quot;JavaScript&quot; SRC=&quot;selectbox.js&quot;></SCRIPT>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>
</HEAD>
<BODY>

</head>
<body>

<FORM>

<TABLE BORDER=0>
<TR>
<TD>
<SELECT NAME=&quot;list11&quot; MULTIPLE SIZE=10 onDblClick=&quot;moveSelectedOptions(this.form.list11,this.form.list21,false)&quot;>
<%
Dim a
DIM l
Dim Pal_Date
dim x
Dim Dateads
Dim DateADD
Dim COunt
DIM Y

a = 02071011 ' this is a source code all it is dd/mm/yy/hh

Pal_Date = mid(a, 5, 2) & &quot;/&quot; & mid(a, 3, 2) & &quot;/&quot; & mid(a, 1, 2) & &quot; &quot; & mid(a, 7, 2)& &quot;:&quot; & &quot;00&quot;
'x = formatdatetime(Pal_Date)
for l = 0 to 168
DateADs = dateadd(&quot;h&quot;,1,Y) ' This SHOULD increments hour
%>
<OPTION><%=Dateads%></OPTION>
<%
next
%>

</SELECT>
</TD>
<TD VALIGN=MIDDLE ALIGN=CENTER>
<INPUT TYPE=&quot;button&quot; NAME=&quot;right&quot; VALUE=&quot;>>&quot; ONCLICK=&quot;moveSelectedOptions(this.form.list11,this.form.list21,false)&quot;><BR><BR>
<INPUT TYPE=&quot;button&quot; NAME=&quot;right&quot; VALUE=&quot;All >>&quot; ONCLICK=&quot;moveAllOptions(this.form.list11,this.form.list21,false)&quot;><BR><BR>
<INPUT TYPE=&quot;button&quot; NAME=&quot;left&quot; VALUE=&quot;<<&quot; ONCLICK=&quot;moveSelectedOptions(this.form.list21,this.form.list11,false)&quot;><BR><BR>
<INPUT TYPE=&quot;button&quot; NAME=&quot;left&quot; VALUE=&quot;All <<&quot; ONCLICK=&quot;moveAllOptions(this.form.list21,this.form.list11,false)&quot;>
</TD>
<TD>
<SELECT NAME=&quot;list21&quot; MULTIPLE SIZE=10 onDblClick=&quot;moveSelectedOptions(this.form.list21,this.form.list11,false)&quot;>


</SELECT>
</TD>
</TR>
</TABLE>

</FORM>


<P></P>
<P></P>
<P></P>
<P></P>
<INPUT type=&quot;button&quot; value=&quot;Button&quot; onclick=window.close() id=button1 name=button1>

</BODY>
</HTML>


Thanks you for any advise

Sammy
 
1) It would probably be better to create two select boxes and allow the user to select a date and time seperately. Than you would only need a loop from 1 to 24 to create the hours, and a loop from 0 to 6 to create selections from Now ot Now + 6 days (For i = 0 to 6 Response.Write &quot;<option>&quot;&dateAdd(&quot;d&quot;,i,Now)&&quot;</option>&quot; Next)
This way instead of having to select one of 168 options in your select box, they choose 1 of 7 options and 1 of 24 options.
As a possible solution without changing the format, I don't see where the variable Y is initialized, so it may be hard to use a dateAdd on it.

2)Place all of the select's inside a form and add a submit button. The when the page is submitted have the next page make your database connection and insertion.

-Tarwn &quot;If you eat a live toad first thing in the morning, nothing worse will happen all day long.&quot; - California saying
&quot;To you or the toad&quot; - Niven's restatement of California saying
&quot;-well most of the time anyway...&quot; - programmers caveat to Niven's restatement of California saying
(The Wiz Biz - Ri
 
Thanks for response but i have to convert data back to source code each time i loop and insert item into listbox bascially

sorry code was test Y isnt in the working copy

<%
Dim a
DIM l
Dim Pal_Date
dim x
Dim Dateads
Dim DateADD
Dim COunt


a = 02071011 ' this is a source code all it is dd/mm/yy/hh

Pal_Date = mid(a, 5, 2) & &quot;/&quot; & mid(a, 3, 2) & &quot;/&quot; & mid(a, 1, 2) & &quot; &quot; & mid(a, 7, 2)& &quot;:&quot; & &quot;00&quot;
'x = formatdatetime(Pal_Date)
for l = 0 to 168
DateADs = dateadd(&quot;h&quot;,1,Pal_Date) ' This SHOULD increments hour
%>
<OPTION><%=Dateads%></OPTION>
<%
next
%>



 
Your comment above is misleading, it appears you are actually storing the date as yy/dd/mm/hh according to your mid statements. You never actually convert that string to a date type, try
Code:
<%
    Dim a, i
    Dim Pal_Date
    dim x
    Dim Dateads
'    Dim DateADD
    Dim COunt
    
'a must be a string in order for mid to pick up the positions correctly, if it is a number than the first position is 0 instead of 1 and the mid() function will not allow 0 as an argument in this case
a = &quot;10070211&quot;  ' this is a source code all it is mm/dd/yy/hh

Pal_Date = dateSerial(cInt(mid(a, 5, 2)) , mid(a, 1, 2) , mid(a, 3, 2))
Pal_Date = dateAdd(&quot;h&quot;,cInt(mid(a, 7, 2)),Pal_Date)

Response.Write &quot;p: &quot;&Pal_Date&&quot;<br>&quot;

    for i = 0 to 168
		DateADs = dateadd(&quot;h&quot;,i,Pal_Date) ' This increments hour
		%><option><%=DateADs%></option><%
    next
%>
I reordered your date string as well as making it a string instead of a number, the explanation is commented above.

Also don't declare dateAdd, that is a function and can't be used as a variable name.

I think i have figured out what I was missing now, basically you have a filled listbox and an empty list box and you are moving selected dates from one to the other, then you want to submit all of the dates in the second list box into the db. What may make this easier is if you add a hidden field and have it hold the contents of the second list box because the list boxes only pass the selection to the next page, not their entire contents, example:
Code:
<HTML>
<HEAD>
<META NAME=&quot;GENERATOR&quot; Content=&quot;Microsoft Visual Studio 6.0&quot;>
<TITLE></TITLE>

<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
function moveSelectedOptions(elemList1,elemList2,bool){
	// ignore following code it is only to duplicate what I think you
		// may have already in your include
	var opt, selOne;
	selOne = elemList1.selectedIndex;

	opt = new Option(elemList1.options[selOne].text,&quot;&quot;);
	elemList2.options[elemList2.options.length] = opt;
	elemList1.options[selOne] = null;

	elemList1.selectedIndex = selOne;
	elemList2.selectedIndex = elemList2.options.length - 1
}

function moveAllOptions(elemList1,elemList2,bool){

}

//this new function handles populating the list, it will need to be called below as shown
function fillHiddenList(elemList,elemHdn){
	var i;

	//re-initialize the value of the hdn field
	elemHdn.value = &quot;&quot;;

	//check that there is at least one value in list
	if(elemList.options.length > 0){			// > 0 options
		elemHdn.value = elemList.options[0].text;	// assign first value
		for(i = 1;i < elemList.options.length;i++){	//loop through any remaining items
			elemHdn.value += &quot;,&quot;+elemList.options[i].text;
		}
	}
}
//-->
</SCRIPT>
</HEAD>
<BODY>

<FORM name=&quot;frmBody&quot; action=&quot;targetPageName.asp&quot; method=&quot;POST&quot;>

<TABLE BORDER=0>
<TR>
    <TD>
    <SELECT NAME=&quot;list11&quot; MULTIPLE SIZE=10 onDblClick=&quot;moveSelectedOptions(this.form.list11,this.form.list21,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;>

<%
    Dim a, i
    Dim Pal_Date
    dim x
    Dim Dateads
'    Dim DateADD
    Dim COunt
    
'a must be a string in order for mid to pick up the positions correctly, if it is a number than the first position is 0 instead of 1 and the mid() function will not allow 0 as an argument in this case
a = &quot;10070211&quot;  ' this is a source code all it is mm/dd/yy/hh

Pal_Date = dateSerial(cInt(mid(a, 5, 2)) , mid(a, 1, 2) , mid(a, 3, 2))
Pal_Date = dateAdd(&quot;h&quot;,cInt(mid(a, 7, 2)),Pal_Date)

Response.Write &quot;p: &quot;&Pal_Date&&quot;<br>&quot;

    for i = 0 to 168
		DateADs = dateadd(&quot;h&quot;,i,Pal_Date) ' This increments hour
		%><option><%=DateADs%></option><%
    next
%>

   </SELECT>
    </TD>
    <TD VALIGN=MIDDLE ALIGN=CENTER>
        <INPUT TYPE=&quot;button&quot; NAME=&quot;right&quot; VALUE=&quot;>>&quot; ONCLICK=&quot;moveSelectedOptions(this.form.list11,this.form.list21,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;><BR><BR>
        <INPUT TYPE=&quot;button&quot; NAME=&quot;right&quot; VALUE=&quot;All >>&quot; ONCLICK=&quot;moveAllOptions(this.form.list11,this.form.list21,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;><BR><BR>
        <INPUT TYPE=&quot;button&quot; NAME=&quot;left&quot; VALUE=&quot;<<&quot; ONCLICK=&quot;moveSelectedOptions(this.form.list21,this.form.list11,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;><BR><BR>
        <INPUT TYPE=&quot;button&quot; NAME=&quot;left&quot; VALUE=&quot;All <<&quot; ONCLICK=&quot;moveAllOptions(this.form.list21,this.form.list11,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;>
    </TD>
    <TD>
    <SELECT NAME=&quot;list21&quot; MULTIPLE SIZE=10 onDblClick=&quot;moveSelectedOptions(this.form.list21,this.form.list11,false);fillHiddenList(this.form.list21,this.form.txtFullList);&quot;>
        
        
    </SELECT>
	This field is text only as an example, it should be changed to type hidden: <input type=&quot;text&quot; name=&quot;txtFullList&quot; value=&quot;&quot;>
    </TD>
</TR>
</TABLE>


</FORM>


<P></P>
<P></P>
<P></P>
<P></P>
<INPUT type=&quot;button&quot; value=&quot;Button&quot; onclick=window.close() id=button1 name=button1>

</BODY>
</HTML>

then to seperate out the individual dates on the next page (called targetPageName.asp in my example) you would use the ASP Split function ( myArray = Split(stringName,delimiter) ) and the delimiter would be &quot;,&quot;

Than you could loop through the new array, sending the new values to your database.

-Tarwn &quot;If you eat a live toad first thing in the morning, nothing worse will happen all day long.&quot; - California saying
&quot;To you or the toad&quot; - Niven's restatement of California saying
&quot;-well most of the time anyway...&quot; - programmers caveat to Niven's restatement of California saying
(The Wiz Biz - Ri
 
THANKS YOU VERY MUCH MY FRIEND EXACTLY WHAT I NEEDED :)

Sammy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top