Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I exclude HTML form radio button values from being submitted?

I need to submit just one input field value to a cgi script via a web form.

I've added a couple of extra form controls (a check box and radio buttons) which manipulate the input value depending on the states selected.

When the form is submitted, the extra form field values are submitted as well which breaks the cgi script (which I don't have access to). I removed the 'name' attribute from the check boxes so they are not submitted but cannot do this for the radio buttons as it breaks their grouping.

How can I prevent radio button values from being submitted?

like image 870
pelms Avatar asked Nov 08 '10 16:11

pelms


People also ask

How do I restrict radio buttons in HTML?

You can check a radio button by default by adding the checked HTML attribute to the <input> element. You can disable a radio button by adding the disabled HTML attribute to both the <label> and the <input> .

How do you make a radio button not clickable in HTML?

Answer: To make a radio button not selectable, in the button's INPUT tag you can use an onclick event handler like this: <INPUT type="radio" name="myButton" value="theValue" onclick="this. checked=false; alert('Sorry, this option is not available!')

Can radio buttons be unselected?

For most controls you may “un-choose” a selection you make. (Required elements may catch you with a note or error message later.) But you cannot click or tap a selected radio button to deselect it. The finality of the action of selecting is not conveyed when none are selected by default.


2 Answers

You can add a disabled attribute to them in the submit handler, this will prevent them from being serialized, either by jQuery or a normal <form> submission. For example:

$("#myForm").submit(function() {
  $(this).find(":radio, :checkbox").attr("disabled", true);
});

Or you can .serialize() only the elements you want, for example:

$.post("myPage.cgi", $("#myForm input[type=text]").serialize());
like image 103
Nick Craver Avatar answered Sep 23 '22 16:09

Nick Craver


Make them "unsuccessful". There are several ways to achieve this: http://www.w3.org/TR/html401/interact/forms.html#h-17.13.2

like image 43
AndreKR Avatar answered Sep 23 '22 16:09

AndreKR