PDA

View Full Version : Change alert box message based on checked value


BigDaddy
03-04-2004, 04:50 PM
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. :)

whammy
03-04-2004, 05:23 PM
Hi Kieth!


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

BigDaddy
03-04-2004, 05:34 PM
Thanks. It works great. :thumbsup:

glenngv
03-05-2004, 08:19 AM
<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)" />