Forum Moderators: open
What I ment was that the radio buttons have the same input name. I'm using PHP as my mailer and the radio buttons have the same input name (q08) for question 8. The values are different. :) I would like at least one button selected as a requirement. Also, I'd like to at least have one selection on a list menu. I'm using DW 8.
Thanks.
They'd have to.
I'm using DW 8.
I'm using my fingers. :)
---------------------------------------
It's not so hard. Referencing the group by name returns a node list.
Just loop through until you find one checked, or return false if none found.
function hasASelection(groupName)
{
var elms = document.getElementsByName(groupName);
/* or use the old-style:
document._form_name_.elements[groupName];*/
for(var k=0, elm;elm=elms[k];k++)
if(elm.checked) return true;
return false;
}
<tr>
<td colspan="5"><span class="style3">
<input name="q07" type="radio" value="When do you plan on attending = ASAP" />
ASAP
<input name="q07" type="radio" value="When do you plan on attending = 2 weeks" />
Two weeks
<input name="q07" type="radio" value="When do you plan on attending = 4 weeks" />
Four weeks
<input name="q07" type="radio" value="When do you plan on attending = Not sure" />
Not sure </span></td>
</tr>
Thanks.
Seeing that you're trying very hard to divert the attention from me to you, it's a scary thought that your gibberish is probably your normal dialect. It took me seconds to read your colloquialisms, and minutes for you to write. Wasted energy my friend.
Thanks for the laugh.
Don't you think "Not sure" has that covered?
<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>test</title>
<script type="text/javascript">function validate(form)
{
var pass = true;
/*
Some other validation stuff
*/
if(! hasASelection('q07') )
{
alert("Please indicate when you plan on attending");
pass = false;
}
return pass;
}
function hasASelection(groupName)
{
var elms = document.getElementsByName(groupName);
for(var k=0, elm;elm=elms[k];k++)
if(elm.checked) return true;
return false;
}
</script>
</head>
<body>
<form action="formscript.php" onsubmit="return validate(this)">
ASAP:
<input name="q07" type="radio" value="When do you plan on attending = ASAP" /><br>
Two weeks:
<input name="q07" type="radio" value="When do you plan on attending = 2 weeks" /><br>
Four weeks:
<input name="q07" type="radio" value="When do you plan on attending = 4 weeks" /><br>
Not sure:
<input name="q07" type="radio" value="When do you plan on attending = Not sure" /><br>
<input type="submit" value="submit" />
</form>
</body>
</html>
is it just bad practice not to validate the form in that way? because i cant see how just checking a *no value* radio button would not work.
I am not saying that i am right or that you are wrong or anything i am just curious to know. Is it w3 regulation or something?
Ally
Actually, there can be an ethical or legal dimension. "click wrap" agreements, such as those in software installers:
[ I agree]
[I do not agree]
with the above terms and conditions
I wouldn't be half-surprised if a default [I agree] radio is illegal in many jurisdictions.
If you want to make sure that the user makes a choice, and makes that choice conciously, then you shouldn't have a default choice that can simply be "clicked through".
If there is a "not sure" option, you might want to make 100% sure that the user doesn't casually miss the opportunity to be more specific.
If the default colour is pink, then it may not placate the customer when you tell them this arrangement when they complain about the colour of their new shoes. They may even be able to legally claim their money back - who knows?
Kaled.
function ufm_validateRadioGroup(rb)
// rb = radio button : return true if any in its group is checked
{ var tmp = eval('rb.form.' + rb.name);
if (tmp) for (var i = 0; i < tmp.length; i++) if (tmp[i].checked) return 1
}