radio button, check for use

F

frits

I have the following code:

<input type="radio" id="q1" name="q1" value="Yes">
<input type="radio" id="q1" name="q1" value="No">

Now I want to check if the button q1 is used so the code must be extended.
When the button is not used, the value must be "q1 not used".

How can I do that? I will not use the "checked" option in the code if it is
showed in the site.
When there is a hidden "checked" option than the value of q1 is always "q1
not used" what can be a solution....

Frits
 
J

Jukka K. Korpela

Scripsit frits:
I have the following code:

<input type="radio" id="q1" name="q1" value="Yes">
<input type="radio" id="q1" name="q1" value="No">

That's odd, because
a) there is no explanation of what is being selected (no labels) - your real
page might have, but why didn't you post the URL of the real page?
b) there is no preselected button in the set, so if the user takes no action
on them, the submitted data depends on the browser (either no data from this
set or q1=Yes)
c) this is a Yes/No choice, which might be better presented as one
checkbox - assuming that it is useful to make a negative answer (no choice)
the default.

The id values shall be distinct, as Adrienne pointed out, but this problem
does not affect the question at hand. It would be particularly relevant
though if you added said:
Now I want to check if the button q1 is used so the code must be
extended.

Which button q1? There are two buttons you are calling q1. Maybe you meant
_a_ q1 button?
When the button is not used, the value must be "q1 not
used".

Then you would add e.g.
<label><input type="radio" name="q1" value="q1 not used" checked>(Please
select one of the above) said:
How can I do that? I will not use the "checked" option in the code if
it is showed in the site.

You just painted yourself in the corner.

Oh well, you _could_ set display: none in CSS for the added element and hope
that all browsers treat an invisible radio button as an existing radio
button.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,002
Messages
2,570,258
Members
46,858
Latest member
FlorrieTuf

Latest Threads

Top