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?? Link to comment https://forums.phpfreaks.com/topic/54776-help-how-to-combine-alert-and-confirmation/ 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"> Link to comment https://forums.phpfreaks.com/topic/54776-help-how-to-combine-alert-and-confirmation/#findComment-270950 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 Link to comment https://forums.phpfreaks.com/topic/54776-help-how-to-combine-alert-and-confirmation/#findComment-271011 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. Link to comment https://forums.phpfreaks.com/topic/54776-help-how-to-combine-alert-and-confirmation/#findComment-271022 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.