Setting checked of Radio from ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mileshenley
    New Member
    • Jan 2009
    • 6

    #1

    Setting checked of Radio from ASP

    Hey there,

    Im relatively new to ASP and am having a bit of a situation and so far google hasn't been too helpful! so hopefully someone here can help!

    Heres is the situation.

    I have a form with a bunch of text and radio fields that load up empty or with some default radio value. what im trying to do is based on a DB Query if there is a ?recordId= in the url, if the record already exists have the fields filled in so they can be editted.

    I haven't had any problems changing the text fields. I just used ASP to write some Response.write some java script basically doing

    FormName.FieldN ame.value =

    and it works fine.

    What i cant figure out is how you can change radio values checked values using a similar method.

    If anyone can help me out please let me know!! thank you! :)

    Miles!

    P.S. If it helps here is how the radios are set up. This is default if it is a new record. Each responsibility has 3 radio options associated with it. Add, Delete, and No Change. But the number of responsibilitie s is dynamic and queried from database.

    Code:
     
    
    <%
    SQL_query1 = "SELECT * FROM casResponsibility ORDER BY casGroup ASC"
    Set RS1 = MyConn.Execute(SQL_query1) 
    %>
     
    <tr> 
    <td><input name="<%=RS1("casRespId")%>" type='radio' value='add' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','block');changeDiv('" & RS1("casRespId") & "delete','none')")%>" /></td>
    <td><input name="<%=RS1("casRespId")%>" type='radio' value='delete' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','none');changeDiv('" & RS1("casRespId") & "delete','block')")%>" /></td> 
    <td><input name="<%=RS1("casRespId")%>" type='radio' value='nochange' onclick="<%Response.write("changeDiv('" & RS1("casRespId") & "add','none');changeDiv('" & RS1("casRespId") & "delete','none')")%>" checked="checked" /></td> 
     
    <td><%=RS1("casGroup")%>-<%=RS1("casTask")%></td>
     
    </tr>
     
    <% RS1.MoveNext %>
    <% WEND %>
    Last edited by DrBunchman; Jan 27 '09, 09:06 AM. Reason: Added [Code] Tags - Please use the '#' button
  • jhardman
    Recognized Expert Specialist
    • Jan 2007
    • 3405

    #2
    As an ASP user, I would have to say that using asp to send a javascript command to change the value of a field is not the easy way to do it. All you need to do is use ASP to fill in the value of the field as you write it: [code=asp]<tr>
    <td><input name="<%=RS1("c asRespId")%>" type="radio" value="add" onclick="change Div('<%=RS1("ca sRespId")%>add' , 'block'); changeDiv('<%= RS1("casRespId" )%>delete','non e')"
    <% if not RS1.eof then response.write "Checked=" & chr(34) & "checked" & chr(34) %>
    /></td>[/code]I wasn't sure exactly which field you were checking, So my if statement just says if the recordset hasn't reached the end, then print "checked", I know there is probably no reason to write that, but hopefully it demonstrates what I am saying. Instead of generating javascript to change the value after it has been written, ASP's strength is altering the text and filling in blanks BEFORE it goes to the browser. Does this make sense?

    Jared

    Comment

    • mileshenley
      New Member
      • Jan 2009
      • 6

      #3
      That is prefect thank you! i had wanted to do something like that but i couldnt figure out how to do 3 levels of " marks. but using char(34) is exactly what i needed. thanks!

      Comment

      • jhardman
        Recognized Expert Specialist
        • Jan 2007
        • 3405

        #4
        Another way to add quote marks without escaping them:[code=asp]dim q
        q = chr(34) %>
        <tr>
        <td><input name="<%=RS1("c asRespId")%>" type="radio" value="add" onclick="change Div('<%=RS1("ca sRespId")%>add' , 'block'); changeDiv('<%= RS1("casRespId" )%>delete','non e')"
        <% if not RS1.eof then response.write "Checked=" & q & "checked" & q %>
        /></td>[/code]Jared

        Comment

        Working...