Link to home
Start Free TrialLog in
Avatar of sherly
sherly

asked on

Disabled TextBox If CheckBox is not selected.

Hello, I have an ASP page that dynamically generates form with checkboxes(products) and textboxes(quantity).
What I need to do it to integrate Javascript into the following source code so it will disable the input of quantity if the product is not selected(checked).
Therefore, if there are 4 products retrieved from database. They will be 4 checkboxes displayed along with their corresponding Quantity textbox. If the 1st product is not checked, its quantity will be disabled. Any idea on this?



<%

DIM DBRead
Set conn = Server.CreateObject("ADODB.CONNECTION")
Set RS = Server.CreateObject("ADODB.RECORDSET")
conn.open "EPCC
SQL = "Select products from customer where username='inti'"
RS.open SQL,conn
Rec = RS("products")
Rec = replace(Rec,".","")

DBRead = split(Rec,",")
Response.Write "<form onsubmit=return checkform(this) method=post action=QuatProc.asp>"
For Each DBR in DBRead
   Response.Write "<input type=Checkbox Name=Products value="&DBR&">" & DBR & " " & "<input type=text name=Qty size=4 maxlength=4>" & "<br>"
Next
Response.Write "<p><input type=submit name=Submit value=Submit></p>"
Response.Write "</form>"
RS.close
set DBRead = nothing
set rs = nothing
conn.close
set conn=nothing
%>
ASKER CERTIFIED SOLUTION
Avatar of nimaig
nimaig
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Michel Plungjan
Dim count=0;

for each

Response.write "<input type=Checkbox Name=Products"&count&" value="&DBR&" onClick=\"this.form.qty"&count&".disabled=!this.checked>" & DBR & " " &
"<input type=text name=Qty"&count&" size=4 maxlength=4 disabled onFocus=\"if (this.disabled) this.blur()\">" & "<br>"
count = count + 1
.
.
.
%>
<script>
// Netscape code
for (i=0;i<document.forms[0].elements.length;i++) {
   if (document.forms[0].elements[i].name.indexOf('Qty')!=-1)
      document.forms[0].elements[i].disabled=true;
}
</script>
I wish I could write VBScript faster :(

Michel
Avatar of sherly
sherly

ASKER

How do I integrate this javascript into my existing ASP code?
try this : U may need to work out for escape character


dim i = 0
For Each DBR in DBRead
  i++
  Response.Write "<input type=Checkbox Name=Products" & i & " onclick='enableText(this,\'Qty" & i & "\')' value="&DBR&">" & DBR & " " & "<input type=text
name=Qty" & i & " size=4 maxlength=4 disabled onFocus='checkDisabled(this,\'Products" & i & "\')'>" & "<br>"
Next
You simply change your response.write
with the response.write code I posted after adding a counter

The asp possibly needs debugging - I am not a vbscripter.

Then AFTER the %> you paste the script I wrote.

Michel