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 .CONNECTIO N")
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
%>
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
Set RS = Server.CreateObject("ADODB
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I wish I could write VBScript faster :(
Michel
Michel
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(thi s,\'Produc ts" & i & "\')'>" & "<br>"
Next
dim i = 0
For Each DBR in DBRead
i++
Response.Write "<input type=Checkbox Name=Products" & i & " onclick='enableText(this,\
name=Qty" & i & " size=4 maxlength=4 disabled onFocus='checkDisabled(thi
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
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
for each
Response.write "<input type=Checkbox Name=Products"&count&" value="&DBR&" onClick=\"this.form.qty"&c
"<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].e
if (document.forms[0].element
document.forms[0].elements
}
</script>