I am creating radio buttons with the code below.
Visitor has to choose one thing with JavaScript.
How do I do? I am inexperienced. Please, Can you give me an example one of codes?
function validateForm(frm){
var radios=frm.secilenlnbtipi_id; //radio button as an array-like object
var n=radios.length; //the total number of radio buttons
for(var i=0; i<n; i++){
if(radios[i].checked]) return true;
}
alert('You must choose one item");
return false;
}
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1254">
<script type="text/javascript">
function validateForm(frm){
var radios=frm.secilenlnbtipi_id; //radio button as an array-like object
var n=radios.length; //the total number of radio buttons
for(var i=0; i<n; i++){
if(radios[i].checked]) return true;
}
alert('You must choose one item");
return false;
}
</script>
</head>
Correct the typo:
for(var i=0; i<n; i++){
if(radios[i].checked]) return true;
into
if(radios[i].checked) return true;
learn to use the javascript console in your web browser to spot those syntax errors and make corrections.
The Javascript in the opening form tag: onsubmit="return validateForm(this)"
should be left as is. Do not replace the "this" by "frm"
10-20-2012, 01:55 PM
Adem
Ok, Thank you very much
10-21-2012, 10:36 PM
Adem
hello again,
How do I make multiple radios groups
grup1
grup1
grup1
grup2
grup2
grup2
grup3
grup3
grup3
grup3
For each group mandatory select one.
Thanks
10-23-2012, 11:33 AM
Adem
Can you help please?
10-23-2012, 12:23 PM
deepode
Ok First of all learn to close your input tags
<input type="something" />
Then for groups, just change the name in <input> like ...
HTML Code:
<p>Member for group 1<input type="radio" value="v1" name="group1"></input></p> <p>Member for group 1<input type="radio" value="v1" name="group1"></input></p> <p>Member for group 2<input type="radio" value="v1" name="group2"></input></p> <p>Member for group 2<input type="radio" value="v1" name="group2"></input></p> <p>Member for group 3<input type="radio" value="v1" name="group3"></input></p> <p>Member for group 3<input type="radio" value="v1" name="group3"></input></p>
10-23-2012, 07:02 PM
Adem
Both groups need to control for the select are required
PHP Code:
<script type="text/javascript">
function validateForm(frm){
var radios=frm.secilenkablotipi_id;
var n=radios.length;
for(var i=0; i<n; i++){
if(radios[i].checked) return true;
}
alert('You must choose one item');
return false;
}
</script>
while ($row = mysql_fetch_array($1groupradios)) { radios group1
}
while ($row = mysql_fetch_array($2groupradios)) { radios group2
}