•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 429,899 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,308 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2216 | Replies: 2 | Solved
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Hi,
I have a dynamically generated form, and each listing contains a checkbox named 'del'.
The users checks the 'del' checkbox next to each listing they wish to delete, and click the submit button. If there are multiple listings/checkboxes on the page, then the script I have works quite well, but if there is only one checkbox displayed on the page. If there is only one checkbox, and the user clicks the submit button, it still submits the form even if the single checkbox is not checked.
Here is my script:
This is how the script is called from the opening form tag: onSubmit="return valDelForm(this)"
I have a dynamically generated form, and each listing contains a checkbox named 'del'.
The users checks the 'del' checkbox next to each listing they wish to delete, and click the submit button. If there are multiple listings/checkboxes on the page, then the script I have works quite well, but if there is only one checkbox displayed on the page. If there is only one checkbox, and the user clicks the submit button, it still submits the form even if the single checkbox is not checked.
Here is my script:
<SCRIPT language="JavaScript1.2">
function valDelForm(theForm)
{
var filledIn = false;
// Use the length property to iterate through each Checkbox
// to determine if a selection has been made
for (var counter=0; counter<theForm.del.length; counter++)
if (theForm.del[counter].checked == true){
filledIn = true;
//else{
if (theForm.del.checked == true){
filledIn = true;
}
// }
}
if (filledIn == false){
alert('Please select a listing to delete!');
return(false);
}
return(true);
}
</script>This is how the script is called from the opening form tag: onSubmit="return valDelForm(this)"
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Problem passing data from popup back to parent
- Next Thread: addEvent based on class not id


Linear Mode