473,387 Members | 1,579 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 1827
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

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

Similar topics

11
by: F. Da Costa | last post by:
Hi, This is a strange issue I'v been staring at for half a day now. It concerns catching keys via the onkeydown handler. In IE5+ it works fine but in Moz 1.6 (& Firebird 0.7+) it behaves most...
4
by: hugo2 | last post by:
Most of these characters are not on the standard keyboard. Here's a successful contrivance, with comments & cautions, a little page that works in IE6. <HTML><HEAD><SCRIPT TYPE="text/javascript">...
4
by: PH | last post by:
Does anyone know how to have the pop-up javascript alert, Response.Write("<script language=javascript>alert('HEY!');</script>); , pop-up after the page has been posted back? I am pressing a...
2
by: Jonathan N. Little | last post by:
As part of a JavaScript precheck form validation I noticed a problem with trying to return focus to the field with an error. I have setup a demo page. ...
24
by: Jeremy J Starcher | last post by:
While reading c.l.j, I've noticed that some people prefer and indeed even recommend the use of "window.alert()" over "alert()". I can't find any technical reason to make this distinction, and...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.