Radio Button Selected by Default

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mstella1
    Mivite



    • Apr 2012
    • 338

    #1

    Radio Button Selected by Default

    Hi,

    In PageBuilder is there a way to have a radio button selected by default in a form? The form I have to make needs one to be selected and I am not seeing that anywhere.

    Thanks,
    Mike
  • Nick
    Super Moderator











    • Dec 2011
    • 575

    #2
    mstella1 The Contact Form flex component does not have that feature for radio buttons. I will add this as a feature request and hopefully we can get it added in a future update.
    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment

    • Bruce - PhosphorMedia
      Developer Partner











      • Mar 2006
      • 11256

      #3
      You could probably do this now by using javascript/jquery on the page before the form container.

      e.g. https://stackoverflow.com/questions/...ad-with-jquery
      Bruce Golub
      Phosphor Media - "Your Success is our Business"

      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
      phosphormedia.com

      Comment

      • mstella1
        Mivite



        • Apr 2012
        • 338

        #4
        Originally posted by Bruce - PhosphorMedia View Post
        You could probably do this now by using javascript/jquery on the page before the form container.

        e.g. https://stackoverflow.com/questions/...ad-with-jquery
        Thanks I will give that one a shot later today!

        Comment

        • mstella1
          Mivite



          • Apr 2012
          • 338

          #5
          Originally posted by Nick View Post
          mstella1 The Contact Form flex component does not have that feature for radio buttons. I will add this as a feature request and hopefully we can get it added in a future update.
          Thanks Nick, I guess the other one to add as a feature request is for checkboxes as well. I was going to use that instead for now and having a checkbox "checked" isn't an option.

          Comment

          • mstella1
            Mivite



            • Apr 2012
            • 338

            #6
            Originally posted by Bruce - PhosphorMedia View Post
            You could probably do this now by using javascript/jquery on the page before the form container.

            e.g. https://stackoverflow.com/questions/...ad-with-jquery
            Thanks Bruce!

            I forgot to post what I ended up using in case someone else needs it.

            HTML Code:
            <script>
            document.addEventListener("DOMContentLoaded", function () {
            function checkRadioButtonByValue(value) {
            const radioButtons = document.getElementsByName("mmx_contactform:fields[1]");
            for (const radio of radioButtons) {
            if (radio.value === value) {
            radio.checked = true;
            break;
            }
            }
            }
            
            // Automatically select the desired radio button when the page loads
            checkRadioButtonByValue("Text label here for the option to be selected");
            });
            </script>

            Comment

            Working...
            X