I have some code which contains a Javascript checkbox handler to delete records in a flat-file database.
When more than one checkbox is checked (one box for each record - say two or three), just about anything from 2 or more records get deleted - sometimes the entire database (a lot more than checked).
Clicking just one checkbox is fine and works a treat.
What I would like help to do is change the checkbox to a radio button, where only one radio button is allowed on at any time. Just changing the checkbox to a radio button in the HTML does not do that.
Code:
<INPUT type="Checkbox" name="delete$i" value="$num">
Changed to Radio button as shown.
<INPUT type="Radio" name="delete$i" value="$num">
The Javascript
Code:
<SCRIPT LANGUAGE="JavaScript">
<!--
function submitForm(which) {
df = document.forum
// --- Delete JS not OKAY.
if (which == 'delete') {
var str = ""
for (var i=0; i<$length; i++) {
if (eval('df.delete'+i+'.checked == true')) {
str += eval('df.delete'+i+'.value')+","
}
}
if (str!="") {
df.todelete.value = str.substring(0,str.length-1)
df.command.value = "deleteThreads"
df.submit()
}
else alert('$ierror: $iernotdel')
}
// --- Edit JS - OKAY
else
if (which == 'edit') {
var editselected = false
if (df.toedit.length) { // code needed for only one thread
for (var i=0; i<df.toedit.length; i++) {
if (df.toedit[i].checked == true) {
editselected = true
break
}}}
else {
if (df.toedit.checked == true) {
editselected = true
}} // end new code
if (editselected == false) alert('$ierror: $iernotedt')
else {
df.command.value = "displayEditThread"
df.submit()
}
}
}
//-->
</SCRIPT>
The radio buttons for the edit code works fine and the radio button behave correctly.
The Delete (new) Radio button can have several selected and the resultant multiple delete problems.
Objective:
How to make the delete section work as a functional radio button, where only one button is on at a time.
Note:
I have tried transposing some of the code of the edit radio button, but it was a miserable failure (becuz I just don't know that much about Javascript). The difference being the name in the Delete button and how it grabs the data (name="delete$i").
This Javascript resides inside a Perl script which is fine and works good in its own right.
I hope someone can help me on this please.
Many thanks - Ted