Jump to content

Form question - Simulate submit when selecting from radio button


HenryCan

Recommended Posts

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?

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.