Changing Radio checked values

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

    Changing Radio checked values

    Hey there,

    This may be an ASP question but i think it is more of a JS question.

    I have a web form that i want to have database values loaded into. I have (and want) the form defaulting to unfilled. I now have it checking and updating most the fields if a recordId is added into the url using ASP. My problem lies in changing the radio values.

    Here are some snipets of what I have to try to do this that isn't working.

    -here is how i have the radios set up


    Code:
    Yes <input name="isDelegate" type="radio" value="yes" onclick="changeDiv('delegate','block')" /> 
                            
    No <input name="isDelegate" type="radio" value="no" onclick="changeDiv('delegate','none')" checked="checked" />



    -here is the JS function

    Code:
    function setRadio(FormObj,stringvalue) {
        If(stringvalue == 'yes'){
            FormObj.isDelegate[0].checked = true;
        }
        
    }

    -here is how i am calling it from ASP within the bottom of the form.
    Code:
    <%
    Response.write("<script type='text/javascript'>")
    Response.write("setRadio(this.form,'" & GR("isDelegate") & "');") 
    Response.write("</script>")
    %>
    that second line produces setRadio(this.f orm,'yes'); if printed out to the screen


    I also tried testing it hardcoding the function call in JS as

    Code:
    <script type="text/javascript">
           setRadio(this.form,'yes');
    </script>
    And this didn't work either.

    If anyone can help me it would be greatly appericiated!!
    Last edited by acoder; Jan 22 '09, 06:15 PM. Reason: Added [code] tags
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    The problem is that "this" doesn't refer to what you probably think it does, so pass document.formNa me where formName is the name of the form.

    If this is generated using ASP, why not just use ASP to set the checked property directly in the HTML code?

    Comment

    • mileshenley
      New Member
      • Jan 2009
      • 6

      #3
      Thanks, i actually ended up doing it in ASP as you suggested. a much better idea!

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Yes, JavaScript is a wonderful language, but don't use it when it's not required.

        Glad to hear that you got it working. See you around.

        Comment

        Working...