if radio button value is checked, then ask for something too
Hi guys, as it says on tittle if radio button value is checked, then ask for something too, so below you will see how my page looks like right now, but i want to make it to ask something else after we choose A or B or C or D, i tried in this way (below), but it didn't work, it used to work with select option -s in this way.
the way i tried eg.
Code:
if (form.type.value == "A")
{
if (form.A1.value == "")
{ alert("Please enter A1."); form.A1.focus(); return;}
}
With that style of coding you'd use form.type[counter].value to refer to the selected radio button.
Just to point out a few other issues with your code:
language="javascript" was replaced by type="text/javascript" many years ago.
<!-- --> inside the script is there to hide it from Internet Explorer 2 - it isn't necessary provided that all your visitors are using at least IE3.
The JavaScript ought to be attached immediately before the </body> tag so it doesn't slow the loading of the HTML and so that the HTML is there before the script runs.
alert() is now suitable only for debugging - you should be updating the error messages directly into the HTML using either innerHTML or proper DOM methods.
Since 1997 input fields have not been allowed directly inside a form tag. You should have a fieldset or div tag wrapped around the inputs.
You should wrap the text associated with each radio button inside <label> tags and attach those to the appropriate button so that clicking on the text works as well as clicking the button.
The onclick JavaScript should be moved out of the HTML and included in the JavaScript code instead.
You should be using type="submit" instead of type="button" so tat the form works for those with JavaScript disabled.
But you have specified method="post". You can't use method=post to send data to another HTML page, or even to the same page (which is what #work would imply).
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Hi Old Pedant thank you for your answer, i didn't show the A1 on my page cause i thought you would understand it, it will be required to fill in A1 , it would be any simple input; eg. if he checked the A option (just eg.) // that's not the point, what i want to do is: if A is checked to ask for A1 or more .. on the current style of coding i'm using.
And about the action="#work" i know it's supposed to be action="mail.php" or something like that.
But please if you get it, and you're able to help me, do it.
Hi, felgall thank you for your answer, i honestly respect all the words you said and i know you're right, but please if you can help me too, just do it.
Well, not true in HTML5. But still, doesn't hurt to put one or the other in, even with HTML5.
Well, according to the HTML 4.01 specification (specifically section 17.3), this is technically true. However, I don't know of any web browser that would actually give you a problem over it.
The <fieldset> tag draws a box around the included elements. Ugly IMO. <div> is fine but redundant really.
__________________
All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
The <fieldset> tag draws a box around the included elements. Ugly IMO. <div> is fine but redundant really.
That depends on what CSS you use to style the fieldset or div tags. They can both be styled the same way the only difference is that with a fieldset you can also specify a legend whereas you can't with a div.
I'd suggest using two such tags at least in the one form so that the error messages can be highlighted differently from the rest of the form.
Where you have radio buttons as well as other fields it is also useful to wrap each group of radio buttons so that you clearly identify them as a group.
If you think it looks ugly then that is just because you are not applying the appropriate CSS to it.