469,270 Members | 1,398 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Alert depends on textbox value

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
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript" language="JavaScript">
  5. <!---
  6.  
  7.        function CheckRequiredFields() 
  8.  {
  9.         var isValid = false;
  10.         var errormessage = "";
  11.  
  12.         for(i=0;i<document.check.elements.length;i++)
  13.          {
  14.                if(document.check.elements[i].checked == true)
  15.             {
  16.                 isValid = true;
  17.                 break;
  18.              }
  19.           }
  20.  
  21.             if(isValid == false)
  22.              {
  23.               errormessage += "\n\nPlease check boxes one or more.";  
  24.               alert('NOTE:' + errormessage);
  25.               return false;
  26.               }
  27.               else
  28.              {
  29.               return true;
  30.              }
  31.     }
  32. //-->
  33. </script>
  34. .
  35. .
  36. .
  37. <form name="check" onSubmit="return CheckRequiredFields()" method="post" action="codetesdel.php">
  38.  
[Please use CODE tags when posting source code. Thanks! --pbmods]

how to combine with confirmation delete??
I'm a newbie.. please somebody help me...
Jun 8 '07 #1
4 1778
epots9
1,351 Expert 1GB
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[i].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??
I'm a newbie.. please somebody help me...
a confirmation dialog would be like this:
Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<document.check.elements.length;i++)
  2.          {
  3.             if(document.check.elements[i].checked == true)
  4.             {
  5.                 var answer = confirm ("Are you having fun?") //add
  6.                 if (answer)                               //add
  7.                 {
  8.                     isValid = true;
  9.                     break;
  10.                 }
  11.              }
  12.           }
  13.  
Jun 8 '07 #2
a confirmation dialog would be like this:
Expand|Select|Wrap|Line Numbers
  1. for(i=0;i<document.check.elements.length;i++)
  2.          {
  3.             if(document.check.elements[i].checked == true)
  4.             {
  5.                 var answer = confirm ("Are you having fun?") //add
  6.                 if (answer)                               //add
  7.                 {
  8.                     isValid = true;
  9.                     break;
  10.                 }
  11.              }
  12.           }
  13.  
thank a lot.... that code have work, but if user click cancel in confirmation delete he back to alert "please select one or more"
Jun 8 '07 #3
epots9
1,351 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. function CheckRequiredFields() 
  2. {
  3. var isValid = false;
  4. var errormessage = "";
  5. var answer = false;
  6.  
  7. for(i=0;i<document.check.elements.length;i++)
  8. {
  9. if(document.check.elements[i].checked == true)
  10. {
  11. answer = confirm ("Are you having fun?") //add
  12. if (answer)                               //add
  13. {
  14. isValid = true;
  15. break;
  16. }
  17. }
  18. }
  19.  
  20. if(isValid == false)
  21. {
  22. if(answer)
  23. {
  24. errormessage += "\n\nPlease check boxes one or more."; 
  25. alert('NOTE:' + errormessage);
  26. }
  27. return false;
  28. }
  29. else
  30. {
  31. if(!answer)
  32. {
  33. return false
  34. }
  35. else
  36. {
  37. return true;
  38. }
  39. }
  40. }
  41.  
  42.  
try that, and tell me if it works
Jun 8 '07 #4
pbmods
5,821 Expert 4TB
Moving to the JavaScript forum.
Jun 8 '07 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

By using this site, you agree to our Privacy Policy and Terms of Use.