Jump to content

Form question - Simulate submit when selecting from radio button


HenryCan
Go to solution Solved by Ch0cu3r,

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?

Link to comment
Share on other sites

  • Solution

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>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.