aris1234 Posted June 8, 2007 Share Posted June 8, 2007 Hi... i need help with javascript in php.. I have multiple checkbox in table, how to view messagebox if user not tick a checkbox and I want show alert "please select one or more" and if user tick a checkbox and I want show confirmation "are You sure for delete?" I using code like this if user not tick a checkbox, and this code work if user not tick a checkbox <html> <head> <script type="text/javascript" language="JavaScript"> <!--- function CheckRequiredFields() { var isValid = false; var errormessage = ""; for(i=0;i<document.check.elements.length;i++) { if(document.check.elements.checked == true) { isValid = true; break; } } if(isValid == false) { errormessage += "\n\nPlease check boxes one or more."; alert('NOTE:' + errormessage); return false; } else { return true; } } //--> </script> . . . <form name="check" onSubmit="return CheckRequiredFields()" method="post" action="codetesdel.php"> how to combine with confirmation delete?? Quote Link to comment Share on other sites More sharing options...
kael.shipman Posted June 8, 2007 Share Posted June 8, 2007 Slight modifications (see the "else" under "if (isValid)"): <html> <head> <script type="text/javascript" language="JavaScript"> <!--- function CheckRequiredFields() { var isValid = false; var errormessage = ""; for(i=0;i<document.check.elements.length;i++) { if(document.check.elements.checked == true) { isValid = true; break; } } if(isValid == false) { errormessage += "\n\nPlease check one or more boxes."; alert('NOTE:' + errormessage); return false; } else { return confirm('Sure you want to delete?'); //Returns the value of confirm(). If user clicks "ok", returns true and submits. Otherwise, returns false and doesn't submit. } } //--> </script> . . . <form name="check" onSubmit="return CheckRequiredFields()" method="post" action="codetesdel.php"> Quote Link to comment Share on other sites More sharing options...
aris1234 Posted June 8, 2007 Author Share Posted June 8, 2007 thank for reply, but this Slight modifications code "return confirm('Sure you want to delete?');" not work, confirm delete can't view, still viewing alert after tick checkbox Quote Link to comment Share on other sites More sharing options...
kael.shipman Posted June 8, 2007 Share Posted June 8, 2007 ooooh i didn't see that that was your problem; sorry. are you sure that the elements list that you're manipulating is valid? try putting alert(document.check.elements) somewhere just to make sure you're referencing the list properly. Other than that, I don't know what to tell you. It may just be a little typo somewhere. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.