1
0
-1

If I have a set of Yes/No radio buttons for example, and I wish to SET the value to Yes or No, how do I do that programmatically (i.e. with JavaScript)?

I've been doing some very useful form pre-population work by doing 

$("Form").scope().Form.data["..."] = value

But how do I set the value of a radio button correctly?

The following attempts don't work:

  • $("Form").scope().Form.data["radioTest"] = "0" 
  • Anything involving the setPathData API call
  • document.getElementById('radioTestYes').checked=true
  • $("radioTestYes").trigger('click')


    CommentAdd your comment...

    2 answers

    1.  
      1
      0
      -1

      Finally, today I found the answer.  It's effectively a primitive event simulation that's accepted over most (all?) browsers:


      document.getElementById('radioTestYes').click()
        CommentAdd your comment...
      1.  
        1
        0
        -1

        I would just do this with a calculation rule on the radio button you want to set. E.g.

        if (data.ID1 === true {

        return 'Yes';

        } else {

        return 'No';

        }

        (Or use an else if and return "" for the else.)

        1. Andrew Halliday

          Hi Lin,

          Thanks for the suggestion.  I haven't explained all the details of my requirements here, but suffice it to say I'm looking for a way to change radio buttons from a central point (in code) rather than having to embed custom code every time I want to set a radio button value.  This code will eventually need to work with multiple radio button components as well.  Today, in stead of using the Avoka API, I may have to fall back on jQuery or good old 'DHTML' to achieve this.

          Andrew

        CommentAdd your comment...