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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with a function

Status
Not open for further replies.

sthmpsn1

MIS
Sep 26, 2001
456
US
I am trying to fill some select boxes in automatically. First question is why isn't my alert working? nothing pops up. Second I am trying to add 1 to the number that is returned in the numdays, but my loop is only 1 less than what I want. So I don't think that x is getting the correct value.
My month select boxes fill in correctly, but my year ones do not fill in. Am I storing 2003 correctly?

function fillthemin() {
var themonthchoosen;
var thecurrentyear;
var x = document.form1.numdays.value + 1;

alert(x);return false;

themonthchoosen = document.form1.select1.value;
thecurrentyear ="2003";


for(var i=1;i<=x;i++) {
document.form1[&quot;month&quot; + i].value = themonthchoosen;
document.form1[&quot;year&quot; + i].value = thecurrentyear;

}

}
 
okay I have my addition month working correctly, but my year doesn't fill in. I know that thecurrentyear is getting the value of 2003, but it isn't making the year select boxes that value. Any ideas?

function fillthemin() {
var themonthchoosen;
var thecurrentyear;
var x = eval(document.form1.numdays.value);


themonthchoosen = document.form1.select1.value;
thecurrentyear =&quot;2003&quot;;



for(var i=1;i<=x;i++) {
document.form1[&quot;month&quot; + i].value = themonthchoosen;
document.form1[&quot;year&quot; + i].value = thecurrentyear;

}

}
 
Can you post the HTML from <FORM NAME=form1...> to </FORM>? Sometimes that helps in solving a problem.

Also (this is going to sound weird) but make sure you don't have another function named fillthemin that does exactly the same thing as the one you posted, but without the alert. I mention this only because it sounds like you're saying that there is evidence that the function is executing lines beyond the alert statement without an alert popping up. The only way this can make sense to me is that it is actually a different function being called. So check for another fillthemin or that it is actually fillthemin that is being called.

--Dave
 
I could post the code, but it is close to 2000 lines of code. I will post part

<form name=&quot;form1&quot; method=&quot;post&quot; onSubmit=&quot;return(checkit())&quot;>
<p class=&quot;apartmentwhite&quot;>Please Select which month your timesheet is
for.
<select name = &quot;select1&quot; size=&quot;1&quot; onChange=&quot;if(this.value!= '01') this.form.MonthName.value=this.options[this.selectedIndex].text;&quot;>
<% Do while NOT dbrs.EOF %>
<option value=&quot;<%=dbrs(&quot;monthnumber&quot;).Value%>&quot;>
<%=dbrs(&quot;monthname&quot;).Value %></option>
<% dbrs.MoveNext %>
<% Loop %>
</select><input type=&quot;submit&quot; value=&quot;Show Current Entries&quot; name=&quot;showthem&quot; onClick=&quot;this.form.showanswers.value='5'&quot;>
<input type=&quot;hidden&quot; name=&quot;supervisor&quot; value=&quot;<%=(rs2.Fields.Item(&quot;supervisoremail&quot;).Value)%>&quot;>
<input type=&quot;hidden&quot; name=&quot;MonthName&quot; value =&quot;January&quot;>
<p>Please Select the number of days you will be entering if > 0:
<select name=&quot;numdays&quot; id=&quot;numdays&quot; onChange=&quot;fillthemin()&quot;>
<option value=&quot;1&quot;>1</option>
<option value=&quot;2&quot;>2</option>
<option value=&quot;3&quot;>3</option>
<option value=&quot;4&quot;>4</option>
<option value=&quot;5&quot;>5</option>
<option value=&quot;6&quot;>6</option>
<option value=&quot;7&quot;>7</option>
<option value=&quot;8&quot;>8</option>
<option value=&quot;9&quot;>9</option>
<option value=&quot;10&quot;>10</option>
<option value=&quot;11&quot;>11</option>
<option value=&quot;12&quot;>12</option>
<option value=&quot;13&quot;>13</option>
<option value=&quot;14&quot;>14</option>
<option value=&quot;15&quot;>15</option>
<option selected> </option>
</select>
</p>
<br>
<% If (Request.Form(&quot;select1&quot;) <> &quot;&quot;) Then %>
<%dbrs3.open (&quot;Select * From Timesheet where loginID = '&quot; & loginname& &quot;' and month = '&quot; & monthname(cint(request(&quot;select1&quot;)))& &quot;'&quot; ), dbconn, 0, 1 %>
<table width=&quot;89%&quot; border=&quot;1&quot; align=&quot;center&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot; class=&quot;apartmenttable&quot;>
<tr>
<td>
<div align=&quot;center&quot;><b>Month</b></div>
</td>
<td>
<div align=&quot;center&quot;><b>Date</b></div>
</td>
<td>
<div align=&quot;center&quot;><b>Hours</b></div>
</td>
<td><b>Code</b></td>
</tr>
<%dbrs3.movefirst %>
<%
Dim y
y = 1
%>
<% Do While NOT dbrs3.EOF %>
<tr>
<td class=&quot;apartmentinside&quot;><%=(dbrs3.Fields.Item(&quot;month&quot;).Value)%></td>
<td class=&quot;apartmentinside&quot;>
<%=(dbrs3.Fields.Item(&quot;date&quot;).Value)%>
</td>
<td class=&quot;apartmentinside&quot;>
<%=(dbrs3.Fields.Item(&quot;hour&quot;).Value)%>
</td>
<td class=&quot;apartmentinside&quot;>
<%=(dbrs3.Fields.Item(&quot;code&quot;).Value)%>
</td>
</tr>
<%dbrs3.movenext %>
<%y = y + 1%>
<% Loop %>
</table>
<% dbrs3.close %>
<p><font size=&quot;+1&quot; color=&quot;#FFFF00&quot;>You Must Reselect the Month</font></p>
<p>
<% End If %>
</p>
<p>By submitting this time sheet, the employee acknowledges working his/her
regular work schedule with the exceptions noted below. For non-exempt
employees in determining overtime hours, our workweek is measured
from 12:01 a.m. Monday through 12:00 midnight Sunday. </p>
<table width=&quot;100%&quot; border=&quot;0&quot;>
<tr>
<td width=&quot;33%&quot; class=&quot;apartmentinside&quot;>
<p>Enter Date(s)<br>
(MM/DD/YYYY)</p></td>
<td width=&quot;10%&quot; class=&quot;apartmentinside&quot;>Hours</td>
<td width=&quot;57%&quot; class=&quot;apartmentinside&quot;>Code (see above)</td>
</tr>
<tr class=&quot;apartmentinside&quot;>
<td width=&quot;33%&quot; class=&quot;apartmentinside&quot;>
<select name=&quot;month1&quot; id=&quot;month1&quot;>
<% dbrs.MoveFirst %>
<% Do while NOT dbrs.EOF %>
<option value=&quot;<%=dbrs(&quot;monthnumber&quot;).Value%>&quot;> <%=dbrs(&quot;monthnumber&quot;).Value %></option>
<% dbrs.MoveNext %>
<% Loop %>
</select>
<select name=&quot;day1&quot; id=&quot;day1&quot; >
<% days.MoveFirst %>
<% Do while NOT days.EOF %>
<option value=&quot;<%=days(&quot;day&quot;).Value%>&quot;> <%=days(&quot;day&quot;).Value %></option>
<% days.MoveNext %>
<% Loop %>
</select>
<select name=&quot;year1&quot; id=&quot;year1&quot; >
<% years.MoveFirst %>
<% Do while NOT years.EOF %>
<option value=&quot;<%=years(&quot;year&quot;).Value%>&quot;> <%=years(&quot;year&quot;).Value %></option>
<% years.MoveNext %>
<% Loop %>
</select> </td>
<td width=&quot;10%&quot;>
<div align=&quot;left&quot;>
<input name=&quot;hour1&quot; type=&quot;text&quot; value=&quot;0&quot; size=&quot;4&quot; maxlength=&quot;4&quot;>
</div></td>
<td width=&quot;57%&quot;><select name=&quot;code1&quot; id=&quot;code1&quot; onChange=&quot;showAnswers()&quot;>
<option value=&quot;v&quot;>v</option>
<option value=&quot;j&quot;>j</option>
<option value=&quot;s&quot;>s</option>
<option value=&quot;m&quot;>m</option>
<option value=&quot;o&quot;>o</option>
<option value=&quot;r&quot;>r</option>
<option value=&quot;x&quot;>x</option>
<option selected> </option>
</select> </td>
</tr>
<tr class=&quot;apartmentinside&quot;>
<td width=&quot;33%&quot; height=&quot;28&quot;>
<select name=&quot;month2&quot; id=&quot;month2&quot;>
<% dbrs.MoveFirst %>
<% Do while NOT dbrs.EOF %>
<option value=&quot;<%=dbrs(&quot;monthnumber&quot;).Value%>&quot;> <%=dbrs(&quot;monthnumber&quot;).Value %></option>
<% dbrs.MoveNext %>
<% Loop %>
</select>
<select name=&quot;day2&quot; id=&quot;day2&quot; >
<% days.MoveFirst %>
<% Do while NOT days.EOF %>
<option value=&quot;<%=days(&quot;day&quot;).Value%>&quot;> <%=days(&quot;day&quot;).Value %></option>
<% days.MoveNext %>
<% Loop %>
</select>
<select name=&quot;year2&quot; id=&quot;year2&quot; >
<% years.MoveFirst %>
<% Do while NOT years.EOF %>
<option value=&quot;<%=years(&quot;year&quot;).Value%>&quot;> <%=years(&quot;year&quot;).Value %></option>
<% years.MoveNext %>
<% Loop %>
</select> </td>
<td width=&quot;10%&quot;>
<div align=&quot;left&quot;>
<input type=&quot;text&quot; name=&quot;hour2&quot; size=&quot;4&quot; maxlength=&quot;4&quot;>
</div></td>
<td width=&quot;57%&quot;><select name=&quot;code2&quot; id=&quot;code2&quot; onChange=&quot;showAnswers()&quot;>
<option value=&quot;v&quot;>v</option>
<option value=&quot;j&quot;>j</option>
<option value=&quot;s&quot;>s</option>
<option value=&quot;m&quot;>m</option>
<option value=&quot;o&quot;>o</option>
<option value=&quot;r&quot;>r</option>
<option value=&quot;x&quot;>x</option>
<option selected> </option>
</select> </td>
</tr>
<tr class=&quot;apartmentinside&quot;>
<td width=&quot;33%&quot;><select name=&quot;month3&quot; id=&quot;month3&quot;>
<% dbrs.MoveFirst %>
<% Do while NOT dbrs.EOF %>
<option value=&quot;<%=dbrs(&quot;monthnumber&quot;).Value%>&quot;> <%=dbrs(&quot;monthnumber&quot;).Value %></option>
<% dbrs.MoveNext %>
<% Loop %>
</select>
<select name=&quot;day3&quot; id=&quot;day3&quot; >
<% days.MoveFirst %>
<% Do while NOT days.EOF %>
<option value=&quot;<%=days(&quot;day&quot;).Value%>&quot;> <%=days(&quot;day&quot;).Value %></option>
<% days.MoveNext %>
<% Loop %>
</select>
<select name=&quot;year3&quot; id=&quot;year3&quot; >
<% years.MoveFirst %>
<% Do while NOT years.EOF %>
<option value=&quot;<%=years(&quot;year&quot;).Value%>&quot;> <%=years(&quot;year&quot;).Value %></option>
<% years.MoveNext %>
<% Loop %>
</select> </td>
<td width=&quot;10%&quot;>
<input type=&quot;text&quot; name=&quot;hour3&quot; size=&quot;4&quot; maxlength=&quot;4&quot;>
</td>
<td width=&quot;57%&quot;><select name=&quot;code3&quot; id=&quot;code3&quot; onChange=&quot;showAnswers()&quot;>
<option value=&quot;v&quot;>v</option>
<option value=&quot;j&quot;>j</option>
<option value=&quot;s&quot;>s</option>
<option value=&quot;m&quot;>m</option>
<option value=&quot;o&quot;>o</option>
<option value=&quot;r&quot;>r</option>
<option value=&quot;x&quot;>x</option>
<option selected> </option>
</select> </td>
</tr>
<tr class=&quot;apartmentinside&quot;>
<td width=&quot;33%&quot;><select name=&quot;month4&quot; id=&quot;month4&quot;>
<% dbrs.MoveFirst %>
<% Do while NOT dbrs.EOF %>
<option value=&quot;<%=dbrs(&quot;monthnumber&quot;).Value%>&quot;> <%=dbrs(&quot;monthnumber&quot;).Value %></option>
<% dbrs.MoveNext %>
<% Loop %>
</select>
<select name=&quot;day4&quot; id=&quot;day4&quot; >
<% days.MoveFirst %>
<% Do while NOT days.EOF %>
<option value=&quot;<%=days(&quot;day&quot;).Value%>&quot;> <%=days(&quot;day&quot;).Value %></option>
<% days.MoveNext %>
<% Loop %>
</select>
<select name=&quot;year4&quot; id=&quot;year4&quot; >
<% years.MoveFirst %>
<% Do while NOT years.EOF %>
<option value=&quot;<%=years(&quot;year&quot;).Value%>&quot;> <%=years(&quot;year&quot;).Value %></option>
<% years.MoveNext %>
<% Loop %>
</select> </td>
<td width=&quot;10%&quot;>
<input type=&quot;text&quot; name=&quot;hour4&quot; size=&quot;4&quot; maxlength=&quot;4&quot;>
</td>
<td width=&quot;57%&quot;><select name=&quot;code4&quot; id=&quot;code4&quot; onChange=&quot;showAnswers()&quot;>
<option value=&quot;v&quot;>v</option>
<option value=&quot;j&quot;>j</option>
<option value=&quot;s&quot;>s</option>
<option value=&quot;m&quot;>m</option>
<option value=&quot;o&quot;>o</option>
<option value=&quot;r&quot;>r</option>
<option value=&quot;x&quot;>x</option>
<option selected> </option>
</select> </td>
</tr>
 
I figured it out, the spaces in the year select box was causing it.
 
What browser are you using? In IE/6, a small-scale version of this works for me IF I have an option in the select-list-of-interest with that value. Perhaps there is not one in your list?

Again, I'm using IE/6. Perhaps what you're using would respond better to something like:

Code:
 var oList = document.form1[&quot;year&quot;+i].options;
 for(i=0; i<oList.length; i++)
 {
  if(oList[i].value == currentyear)
  {
   oList[i].selected=true;
   break;
  }
 }

...than to:

Code:
document.form1[&quot;year&quot;+i].value = currentyear;

'just a couple of ideas. I don't know if either of these is your solution though.

Good luck.

--Dave
 
Ah. I just saw your message that you figured it out. Nevermind!

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top