HenryCan Posted September 15, 2014 Share Posted September 15, 2014 I'm developing a form which is essentially a simple set of radio buttons. Conceptually, it is like this: Please select a theme from the list: o Black o Blue o Red [submit] [Reset] I'm actually showing a slideshow of images showing the appearance of each of the themes in a slideshow that only shows one image at a time. I want my users to click on the image that represents the theme they want and, ideally, not have to click on the Submit button at all. Then I will save the name of the theme they chose in a cookie (if cookies are enabled). Many years ago, I dabbled in things like CGI and I have a vague recollection, possibly faulty, that it's not difficult to make a form that has only one set of radio buttons treat the selection of one of the radio buttons as a Submit. I don't remember how to do it though. Can anyone advise me on whether it is indeed possible and, if it is, how I make the selection of the radio button cause the form to be submitted? Quote Link to comment https://forums.phpfreaks.com/topic/291082-form-question-simulate-submit-when-selecting-from-radio-button/ Share on other sites More sharing options...
Solution Ch0cu3r Posted September 15, 2014 Solution Share Posted September 15, 2014 To submit the form you'd need to use javascript when the user selects a radio button. Example using JQuery <form action="process.php" method="post" id="myForm"> <input type="radio" class="color_select" name="color" value="red" /> Red<br /> <input type="radio" class="color_select" name="color" value="blue" /> Blue<br /> <input type="radio" class="color_select" name="color" value="green" /> Green<br /> </form> <script src="https://code.jquery.com/jquery-2.1.1.min.js"></script> <script> // apply on click handler to radio buttons $('.color_select').on('click', function(e) { $('#myForm').submit(); // submit the form }); </script> Quote Link to comment https://forums.phpfreaks.com/topic/291082-form-question-simulate-submit-when-selecting-from-radio-button/#findComment-1491187 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.