Web Analytics Made Easy -
StatCounter Change alert box message based on checked value - CodingForum

Announcement

Collapse
No announcement yet.

Change alert box message based on checked value

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Change alert box message based on checked value

    Hi. I have a checkbox, that if checked, I want to put up an alert box saying the record will be deleted. Conversely, if the user then unchecks the checkbox, I don't want any message to show up Here's what I have.

    On my checkbox, I'm doing an "onclick = ConfirmChoice(this);"

    My script:

    function ConfirmChoice(x)
    {
    checked = x.value
    if (checked == '')
    {
    alert("boo");
    }
    else
    {
    alert("This record will be deleted when Detail Settings are saved.")
    }
    }


    So far, it always does the 2nd part of the else statement.

    Any help is much appreciated. Thanks.
    This is in spanish when you're not looking.

  • #2
    Hi Kieth!

    Code:
    <script type="text/javascript">
    <!--
    function confirmDelete(fld,chk)
    {
    	var confirmstring = "";
    	if (chk.checked)
    	{
    		confirmstring += "Are you sure you want to delete this thingamabob?\n\n";
    		confirmstring += "To cancel this action, click \"Cancel\".";
    		if (!confirm(confirmstring))
    		{
    			chk.checked = false;
    		}
    	}
    }
    
    // -->
    </script>
    
    <form id="form1" action="" method="post">
    <input type="text" name="test" value="" /> <input type="checkbox" name="" value="" onclick="confirmDelete(this.form.test,this)" />
    </form>
    Former ASP Forum Moderator - I'm back!

    If you can teach yourself how to learn, you can learn anything. ;)

    Comment


    • #3
      Thanks. It works great.
      This is in spanish when you're not looking.

      Comment


      • #4
        alternative solution

        <input type="checkbox" onclick="this.checked=(this.checked)?confirm('Are you sure you want to delete this?'):false;" />

        or in a function:

        function check(obj){
        obj.checked=(obj.checked)?confirm('Are you sure you want to delete this?'):false;
        }
        ...
        <input type="checkbox" onclick="check(this)" />
        Glenn
        vBulletin Mods That Rock!

        Comment

        Working...
        X