user102008
user102008

Reputation: 31323

Can I make a set of radio buttons that does not get submitted with the form?

I have a set of radio buttons that is in between other controls that are part of an HTML form. I do not want the value of these radio buttons to be submitted with the query (I am just using these radio buttons for JavaScript stuff). Normally, I can do this with other controls (i.e. checkboxes, etc.) by not having a "name" attribute for them, and they won't get submitted. However, the "name" attribute is required in order for radio buttons to have their "mutually-exclusive" behavior. I cannot move the radio buttons outside of the form either, because it's situated in between other controls that do need to be submitted with the form. Also, I cannot disable the radio buttons because I need the user to be able to click them. So is there a way I can make a set of radio buttons that do not get submitted with the form?

Upvotes: 0

Views: 481

Answers (3)

McTrafik
McTrafik

Reputation: 2938

If you didn't care about validity, you could still have the radio buttons, and not give them names. Your JS can identify them by their IDs, and without names, they won't pass any parameters.

Upvotes: 0

bpeterson76
bpeterson76

Reputation: 12870

You have a few options on this one.

Upvotes: 0

Sampson
Sampson

Reputation: 268424

I can think of a couple solutions:

Elements in an <iframe />

One would be to place the buttons within an iframe, within your form, and merely turn the border of the iframe off so as to give the impression they are in the form.

Remove during "Submit"

Another solution would be to remove the element from the form via Javascript on the forms submit action, sending a truncated list of elements back to the server.

If it were me, I'd just ignore the elements on the server-side.

Upvotes: 2

Related Questions