Link to home
Create AccountLog in
Avatar of confused_coder
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_status" <% If rs("OrgDescription_status") = cstr("1")  Then
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label>&nbsp;&nbsp;
<input type="radio" name="OrgDescription_status"  value="2" /><label>Minor changes</label><br />
<input type="radio" name="OrgDescription_status"  value="3" /><label>Major Changes</label>&nbsp;
<input type="radio" name="OrgDescription_status"  value="4" /><label>No Changes</label>

also tried this

<input type="radio" name="OrgDescription_status" <% If cstr(rs("OrgDescription_status")) = cstr("1")  Then
response.write "checked='checked'" End If%> value="1" /><label>Full translation</label>&nbsp;&nbsp;
<input type="radio" name="OrgDescription_status"  value="2" /><label>Minor changes</label><br />
<input type="radio" name="OrgDescription_status"  value="3" /><label>Major Changes</label>&nbsp;
<input type="radio" name="OrgDescription_status"  value="4" /><label>No Changes</label>

It has been ages since I've worked in ASP so any help would be appreciated.
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

How is the value stored in the database ? As a text-based type or a numeric ?
Avatar of confused_coder
confused_coder

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_status" <% If Trim(rs("OrgDescription_status")) = "1"  Then
response.write "checked='checked'" %> value="1" />
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_status" <% If Trim(rs("OrgDescription_status")) = "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
-----------------------------------^
Its in an access DB with the field set as text
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
What about:
<input type="radio" name="OrgDescription_status"<% If rs("OrgDescription_status") = cstr("1")  Then %> checked="checked" <%End If%> value="1" />
I found another way of doing 2 secs ago but your way is much shorter.
<% If cstr(rs("OrgDescription_status")) = cstr("1") Then%>
<input name="OrgDescription_status" type="radio"  value="1" checked="checked" /><label>Full translation</label>&nbsp;&nbsp;
<% Else %>
<input name="OrgDescription_status" type="radio"  value="1" /><label>Full translation</label>&nbsp;&nbsp;
<%end if %>  

works but not pretty