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

Cascade Changes in Form

Status
Not open for further replies.

lennitw

Programmer
Jan 10, 2006
13
US
I have a page that requires a user to enter a start time/end time. The user then selects a job from a dropdown list. This will automatically populate the TimePerSqFT box. The user then enters a number in the SqFT box and this would be multiplied by TimePerSqFT and a start time/end time will automatically populate in the appropriate boxes on the same row. The user then clicks "Add Item" and the page reloads with the previous data and a new blank row.

The PROBLEM: The function I have to automatically update the start/end time boxes only works for the current row. I would like to be able to change a value in any box and see all the calculated times change on the page. Below is the code for the page:
========
<!--#include file="include/appsettings.asp"-->
<!--#include file="include/validatescript.asp"-->
<%
'### Open Connection to DB
Set db = Server.CreateObject("ADODB.Connection")
db.Open ms47DSN

cntX = request.form("cntX")
if cntX = "" then
cntX = 2
else
cntX = cntX + 1
end if

if request("additem") = "Add Item" then

elseif request("saveForm") = "Save" then
response.write "SAVE DATA"
end if


%>
<html>

<head>
<meta http-equiv="Content-Language" content="en-us">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>MS47</title>

<script language=VBScript>
sub window_onLoad
PopulateTextbox
end sub

sub PopulateTextbox()
dim x, scX, space_comp, taskid, minper, spacetype, newtime, checktime, varnum, lastVar
x = 0
varnum = document.frmMS47.elements("cntY").value - 1
scX = 0
space_comp = ""
taskid = ""
minper = 0


do until x > LEN(document.frmMS47.elements("SpaceTypeTask" & varnum).value)
if right(left(document.frmMS47.elements("SpaceTypeTask" & varnum).value,x),1) = "-" AND space_comp = "" then
space_comp = left(document.frmMS47.elements("SpaceTypeTask" & varnum).value,x-1)
scX = x
x = x + 1
end if
if right(left(document.frmMS47.elements("SpaceTypeTask" & varnum).value,x),1) = "-" AND taskid = "" then
taskid = right((left(document.frmMS47.elements("SpaceTypeTask" & varnum).value,(x-1))),x-scx-1)
xx = x
minper = right(document.frmMS47.elements("SpaceTypeTask" & varnum).value, LEN(document.frmMS47.elements("SpaceTypeTask" & varnum).value) - x)
x = LEN(document.frmMS47.elements("SpaceTypeTask" & varnum).value)
end if

x = x + 1
loop

document.frmMS47.elements("TimePerSqFt" & varnum).value = minper

if varnum = 1 then
lastVar = 1
else
lastVar = varnum - 1
end if

checktime = document.frmMS47.elements("endtime" & lastVar).value

myDec = InStr(1, CStr(minper * document.frmMS47.elements("sqFT_Fix" & varnum).value), ".", vbTextCompare)
If myDec > 0 Then
roundUp = CDbl(Left(CStr(minper * document.frmMS47.elements("sqFT_Fix" & varnum).value), myDec)) + 1
Else
roundUp = minper * document.frmMS47.elements("sqFT_Fix" & varnum).value
End If

newtime = (DATEADD("n",((roundUp)),checktime))
document.frmMS47.elements("endTime" & varnum).value = formatdatetime(newtime,4)

document.frmMS47.elements("startTime" & varnum).value = formatdatetime(checktime,4)

end sub
</script>

<script>
function PopUp(PopUpUrl){
var ScreenWidth=window.screen.width;
var ScreenHeight=window.screen.height;
var movefromedge=0;
placementx=300;
placementy=100;
WinPop=window.open(PopUpUrl,"","width=400,height=400,toolbar=0,location=0,directories=0,status=0,scrollbars=1,menubar=0,resizable=0,left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}
</script>

</head>

<body>
<form name=frmMS47 action="ms47form_test.asp" method=POST>

<table border="1" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="775" id="AutoNumber2">
<tr>
<td width="771" colspan="9"></td>
</tr>
<tr>
<td width="50" rowspan="2">
<p align="center"><b><font size="2">Item<br>#</font></b></td>
<td width="72" rowspan="2">
<p align="center"><b><font size="2">Equipment<br>Building<br>Identification</font></b></td>
<td width="50" rowspan="2">
<p align="center"><b><font size="2">Space<br>Type &amp; Task</font></b></td>
<td width="110" colspan="2" align="center"><b><font size="2">CALCULATIONS</font></b></td>
<td width="151" colspan="2" align="center"><b><font size="2">TIME</font></b></td>
<td width="53" rowspan="2">
<p align="center"><b><font size="2">Check<br>List #</font></b></td>
<td width="267" rowspan="2">
<p align="center"><b><font size="2">INSTRUCTIONS are Reminders<br>REFER TO MASTER CHECKLIST </font></b></td>
</tr>
<tr>
<td width="50" align="center"><b><font size="1">SQ FOOT<BR>OR FIX</font></b></td>
<td width="57" align="center"><b><font size="1">TIME PER<BR>SQ FT</font></b></td>
<td width="67" align="center"><b><font size="2">FROM</font></b></td>
<td width="81" align="center"><b><font size="2">TO</font></b></td>
</tr>
<tr>
<td width="50">
<p align="center"><b>1</b></td>
<td width="238" colspan="4">
<p align="center"><b><font size="4" color="#FF0000">SAFETY &amp; supplies</font></b></td>
<td width="67">
<p align="center">
<% starttime = request("startTime1")
if starttime = "" then
starttime = "00:00"
end if %>
<input type=text name='startTime1' size=5 maxlength=6 tabindex="1" value="<%=starttime%>"></td>
<td width="81">
<p align="center">
<% endTime = request("endTime1")
if endTime = "" then
endTime = "00:00"
end if %>
<input type=text name='endTime1' size=5 maxlength=6 tabindex="1" value="<%=endTime%>"></td>
<td width="53">
<p align="center"><b>ALL</b></td>
<td width="267">
<p align="center"><font size="2">F</font><b><font size="2">ollow all Safety
Precautions / Get supplies &amp; Proceed to work area. </font></b></td>
</tr>

<% '###### Begin Loop
cntY = 2
do until cntY = cntX + 1
%>
<tr>
<td width="50" align="center">
<p align="center"><b><%=cnty%></b></td>
<td width="72" align="center">&nbsp;</td>
<td width="50" align="center">
<p align="center">
<select size="1" name="SpaceTypeTask<%=cntY%>" onChange="PopulateTextbox();">
<option selected>---</option>
<% sql = "SELECT * FROM RANGE ORDER BY space_comp, taskid;"
set rs = db.Execute(sql)

If NOT(rs.BOF AND rs.EOF) then
do until rs.eof
if request("SpaceTypeTask"&cntY) = rs("space_comp")&"-"&rs("taskid")&"-"&rs("min_per") then
spacetypeSELECTED = "SELECTED"
else
spacetypeSELECTED = ""
end if
response.write "<option "&spacetypeSELECTED&" value='"&rs("space_comp")&"-"&rs("taskid")&"-"&rs("min_per")&"'>"&rs("space_comp")&rs("taskid")&"</option>"
rs.movenext
loop
end if %>
</select> <a title="View Space Types" href="javascript:popUp('help.asp?helptype=spacetype')">?</a></td>
<td width="50" align="center">
<% sqFT_Fix = request("sqFT_Fix"&cntY)
if sqFT_Fix = "" then
sqFT_Fix = 0
end if
%>
<input type=text onBlur="checkNumeric(this,0,100000,'','.','');" onChange="PopulateTextbox();" name='sqFT_Fix<%=cntY%>' size=5 maxlength=6 tabindex="1" value="<%=sqFT_Fix%>">
</td>
<td width="57" align="center">
<input type=text name="TimePerSqFt<%=cntY%>" size=5 maxlength=9 tabindex="1" value="<%=request("TimePerSqFt"&cntY)%>"></td>
<td width="67" align="center">
<% if cntY = 2 then
PrevStartTime = request("endtime1")
else
PrevStartTime = request("endtime"&cntY-1)
end if %>
<input type=text name="startTime<%=cntY%>" size=5 tabindex=1 value="<%=request("endtime"&cntY-1)%>">
</td>
<td width="81" align="center">
<input type=text name="endTime<%=cntY%>" size=5 tabindex=1 value="<%=request("endtime"&cntY)%>">
<% if cntX = cntY then %>
<input onClick="PopulateTextbox();" type="button" value="+" name="B1">
<% end if %>
</td>
<td width="53" align="center">&nbsp;</td>
<td width="267" align="center"><input type="text" name="T1" size="20"></td>
</tr>
<% '###### End Loop
cntY = cntY + 1
loop
%>

<tr>
<td colspan="4" width="231">
<p align="center"><input type="submit" value="Add Item" name="addItem">
<input type="hidden" value="<%=cntX%>" name="cntX">
</td>
<td colspan="5" width="537">
<p align="center"><input type="submit" value="Save" name="saveForm">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Cancel" name="cancelForm">
<input type="hidden" name="cntY" size="1" value="<%=cntY%>"></td>
</tr>

</table>
</form>
</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top