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

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.