confused_coder
asked on
Making a radio button checked based on record in database ASP VBscript
I want to have a radio button checked if the value in the DB is the same as the value of the radio box
<input type="radio" name="OrgDescription_statu s" <% If rs("OrgDescription_status" ) = cstr("1") Then
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label> & nbsp;
<input type="radio" name="OrgDescription_statu s" value="2" /><label>Minor changes</label><br />
<input type="radio" name="OrgDescription_statu s" value="3" /><label>Major Changes</label>
<input type="radio" name="OrgDescription_statu s" value="4" /><label>No Changes</label>
also tried this
<input type="radio" name="OrgDescription_statu s" <% If cstr(rs("OrgDescription_st atus")) = cstr("1") Then
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label> & nbsp;
<input type="radio" name="OrgDescription_statu s" value="2" /><label>Minor changes</label><br />
<input type="radio" name="OrgDescription_statu s" value="3" /><label>Major Changes</label>
<input type="radio" name="OrgDescription_statu s" value="4" /><label>No Changes</label>
It has been ages since I've worked in ASP so any help would be appreciated.
<input type="radio" name="OrgDescription_statu
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label> &
<input type="radio" name="OrgDescription_statu
<input type="radio" name="OrgDescription_statu
<input type="radio" name="OrgDescription_statu
also tried this
<input type="radio" name="OrgDescription_statu
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label> &
<input type="radio" name="OrgDescription_statu
<input type="radio" name="OrgDescription_statu
<input type="radio" name="OrgDescription_statu
It has been ages since I've worked in ASP so any help would be appreciated.
How is the value stored in the database ? As a text-based type or a numeric ?
ASKER
its text based at the moment, but it could easily be switched to numeric if needed.
I can't see any particular reason why it shouldn't be working, unless the DB field is char. Try:
<input type="radio" name="OrgDescription_statu s" <% If Trim(rs("OrgDescription_st atus")) = "1" Then
response.write "checked='checked'" %> value="1" />
<input type="radio" name="OrgDescription_statu
response.write "checked='checked'" %> value="1" />
ASKER
got this errot
Microsoft VBScript compilation error '800a03f6'
Expected 'End'
record.asp, line 378
Microsoft VBScript compilation error '800a0412'
so I added "End If"
<input type="radio" name="OrgDescription_statu s" <% If Trim(rs("OrgDescription_st atus")) = "1" Then
response.write "checked='checked'" End If%>
and got this error
Must be first statement on the line
record.asp, line 70
response.write "checked='checked'" End If
-------------------------- ---------^
Microsoft VBScript compilation error '800a03f6'
Expected 'End'
record.asp, line 378
Microsoft VBScript compilation error '800a0412'
so I added "End If"
<input type="radio" name="OrgDescription_statu
response.write "checked='checked'" End If%>
and got this error
Must be first statement on the line
record.asp, line 70
response.write "checked='checked'" End If
--------------------------
ASKER
Its in an access DB with the field set as text
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
What about:
<input type="radio" name="OrgDescription_statu s"<% If rs("OrgDescription_status" ) = cstr("1") Then %> checked="checked" <%End If%> value="1" />
<input type="radio" name="OrgDescription_statu
ASKER
I found another way of doing 2 secs ago but your way is much shorter.
ASKER
<% If cstr(rs("OrgDescription_st atus")) = cstr("1") Then%>
<input name="OrgDescription_statu s" type="radio" value="1" checked="checked" /><label>Full translation</label> & nbsp;
<% Else %>
<input name="OrgDescription_statu s" type="radio" value="1" /><label>Full translation</label> & nbsp;
<%end if %>
works but not pretty
<input name="OrgDescription_statu
<% Else %>
<input name="OrgDescription_statu
<%end if %>
works but not pretty