• Resolved mihaela02

    (@mihaela02)


    How I can determine what radio button is checked before form submision?
    I have a form with many fields and I want o show some fields if a radio buttton is checked and other fields if the other radio button is checked.
    If you can tell me step by step what I must do. Thanks.

Viewing 7 replies - 1 through 7 (of 7 total)
  • Are you creating your own form plugin?

    Thread Starter mihaela02

    (@mihaela02)

    This form I created in a php file of a theme.

    Sorry but that won’t work in WordPress. You need to effectively create your own plugin and, unless you are relatively experienced with writing plugins, it could be an uphill task. You might be better looking for a free pre-existing form plugin.

    Thread Starter mihaela02

    (@mihaela02)

    Is this possible with Simple User Registration plugin?

    You’d need to ask the author of the plugin this question in that plugin’s dedicated forum via its page in the Plugin Repository. There are simply too many plugins us to know what will, and what won’t, work with each one

    i did one where we used java to check for options counted, then continue. you may be able to mod and use it

    $("#oiSubmitBtn").click(function(){
    var n = $("input:checked").length;
    if(n<3){
    	alert("Select atleast 3 checkbox");
    	return false;
    	}
    });
    Joey

    (@leglesslizard)

    Hey,

    PHP is loaded server side and so does not recognise any user input unless the page is reloaded. As stated above javascript would be the way to go to handle this (the example code shows jQuery (a popular javascript library included in wordpress). You can add javascript to any html code with the use of “<script></script>” tags.

    And something like this should do what you are after. You would need to replace the ids with your own:

    <script>
        jQuery( '#radio_one' ).on( 'click', function() {
            jQuery( '#element_two' ).hide();
            jQuery( '#element_one' ).show();
        }
        jQuery( '#radio_two' ).on( 'click', function() {
            jQuery( '#element_one' ).hide();
            jQuery( '#element_two' ).show();
        }
    </script>

    I’ve tried to write this in a very simple way that’s easy to understand. This looks for an element with id=”radio_one” and when it is clicked, hides element with id=”element_two” and shows element with id=”element_one”. And then the reverse is done when radio_two is clicked.
    Obviously your ids should be meaningful within your code.

    Hope that helps!
    Regards ??

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘radio buttons’ is closed to new replies.