Click to See Complete Forum and Search --> : checkbox --- textbox


jayvit
02-10-2003, 08:12 PM
Hi,

I have some check boxes and equivalent number of text boxes. The number is dynamic (depends upon the number of records returned by recordset).

Now, on clicking a checkbox (any one among the group), I should get '1' displayed in corresponding textbox. a second click, could be anywhere in the group should give a '2' in the corresponding text box. It is some way tracking the priority. On deselecting the checkbox should clear away the corresponding number.

Here is the code
------------------
<form name="myform">
<%
i=0
do until RS.EOF
%>
<td><Input type="checkbox" name="chkbx<%=i%>" value="<%=RS("ComponentID")%>"></td>
<td><Input type=text name="txtQty<%=i%>" size=1 AutoComplete="Off"></td>

<% RS.MoveNext
i=i+1
loop
%>
</form>

Thanks,
Jay

skriptor
02-11-2003, 02:59 AM
Hi,
try something like this:

<script type="text/javascript" language="javascript">
var iCount = 0;

function doIt( iIndex ) {
var tmpVal;
if ( document.myform["chkbx" + iIndex].checked ) {
document.myform["txtQty" + iIndex].value = ++iCount;
} else {
iCount--;
tmpVal = document.myform["txtQty" + iIndex].value;
document.myform["txtQty" + iIndex].value = "";
iIndex = -1;
while( document.myform["txtQty" + (++iIndex)] ) {
if ( document.myform["txtQty" + iIndex].value > tmpVal ) {
document.myform["txtQty" + iIndex].value =
document.myform["txtQty" + iIndex].value - 1;
}
}
}
}
</script>


<td><Input type="checkbox" name="chkbx<%=i%>" onclick="doIt(<%=i%>);" value="<%=RS("ComponentID")%>"></td>

Good luck, Skriptor.