Jump to content

Help: how to combine alert and confirmation


aris1234

Combine alert and confirmation  

  1. 1. Combine alert and confirmation

    • i dont know
      0
    • i dont know
      0


Recommended Posts

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??  ;)

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.