How can I exclude the values ​​of the HTML form radio buttons from the ones presented?

I need to send only one input field value in a cgi script via a web form.

I have added some additional form controls (checkbox and radio buttons) that control the input value depending on the selected states.

When submitting a form, additional values ​​are entered for the form fields that break the cgi script (which I do not have access to). I removed the "name" attribute from the checkboxes so that they would not be sent, but cannot do this for the switches, as it breaks their grouping.

How can I prevent the sending of switch values?

+6
javascript jquery forms
source share
3 answers

You can add the disabled attribute to them in the submit handler; this will not allow them to be serialized, either with jQuery or with a regular <form> . 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()); 
+12
source share

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

+6
source share

It is also possible to have two different forms: one that has visible form elements, and one that has hidden input , which represents the final result to submit. You can bind onchange handlers to your visible form elements so that they invoke some JavaScript to update the invisible field, or you can run the function as part of the onsubmit handler to set the invisible value immediately before submitting.

Here jsFiddle demonstrates the second approach ( onsubmit handler): http://jsfiddle.net/gtU4J/

0
source share

All Articles