1

I am wondering whether you can make a button, function like a HTML Radio button. I am trying to create a form where the user clicks on the said button and a value is thus selected, but the user is not directed until selecting another option and submitting the form. Does anyone know how to go about doing this?

(I don't mind the use of other languages including javascript etc.)

2
  • Can you elaborate? Your question isn't entirely clear. Commented Oct 20, 2011 at 20:23
  • Pretty much the functionality of what the guy posted below. Commented Oct 20, 2011 at 20:25

2 Answers 2

3

jQueryUI has a Button Widget that converts radio buttons or checkboxes into buttons.

Example from the site:

http://jqueryui.com/demos/button/#radio

<script>
$(function() {
    $( "#radio" ).buttonset();
});
</script>

<div class="demo">
    <form>
        <div id="radio">
            <input type="radio" id="radio1" name="radio" /><label for="radio1">Choice 1</label>
            <input type="radio" id="radio2" name="radio" checked="checked" /><label for="radio2">Choice 2</label>
            <input type="radio" id="radio3" name="radio" /><label for="radio3">Choice 3</label>
        </div>
    </form>
</div>

You can visit the link to see it in action.

Sign up to request clarification or add additional context in comments.

Comments

0

First, on the page you're talking about, it sounds as if the user is taken somewhere else -- i.e., a submit-like action is taken -- merely by his selecting a radio button. I don't believe that this is the very best practice.

Second, you should imo keep the two radio buttons: they work great and, once selected, a radio button can't be cleared except by selecting another button. This is just what you want.

To be sure that the two buttons you require have been selected, give each button an onclick handler that sets a switch: some button in this group was selected.

Then, when he clicks submit, check those two switches and tell him if he forgot to click a button.

Yes, you need JavaScript to do all this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.