Click to See Complete Forum and Search --> : Javscript Yes/No Confirmation box


Spidey
11-04-2003, 12:04 PM
HI all,

I tired searching but couldn't find the answer.

For example if I have a form:

<FORM action='<?=$_SERVER['PHP_URI']?>' name="user_registration" method=post onSubmit="return confirm("Are you 18 or older?")">

when i submit this form, it will have a pop up box asking if the user is 18 or older. THe problem is, instead of a confirmation box, I want a yes/no box.

I know in javascript you can have a custom dialog box, but the thing is, I want to use it as a confirmation in this manner, so I would need it to return true or false and then submit my form.

SO that's what I need, can you guys help me? Thanks a lot.

requestcode
11-04-2003, 12:57 PM
Here is an example of creating your own confirm box, but it will need to be modified to work with the onSubmit. Should be do-able.
<html>
<head>
<title>Custom ConFirm, Alert and Prompt</title>
<style>
/* You can modify these styles to anything you want (or is allowed). */
/* These are used by both browsers. You can set these to your preferences. */
.td1style {font-weight:bold;border:1px solid black;background-color:lightgrey;color:blue;font-size:14px;fontFamily:Verdana;}
.td2style {font-weight:bold;border:1px solid black;background-color:lightyellow;font-size:12px;font-family:Verdana;}
/* the style below is for the links that are inside the div when it pops up */
.linkstyle {font-weight:bold;font-size:12px;text-decoration:none}
</style>
<script language="JavaScript">
var msgtop=50 // Set the top position of the div
var msgleft=20 // Set the left position of the div

/* The following three variables are for setting the properties of your table contained within the div. */
var tborder="0"
var cspace="0"
var cpad="0"
var tabheight=50 // Set the height of table
var tabwidth=150 // Set the width of table
var td1height=10
var td2height=30
var boxt=""
function Domsg(flag)
{
hidebox() // Hide the box after clicking on text link in box
if(flag=="Yes")
{
msg="You Clicked "+flag+"!"
}
else
{msg="Why did you click "+flag+"?"}
document.formbx.result.value=msg
}
function DoFormbox(msgtext)
{
theString="<table width='"+tabwidth+"' height='"+tabheight+"' border="+tborder+" cellspacing="+cspace+" cellpadding="+cpad+"><tr><td height='"+td1height+"' class='td1style' align='left'><b>"
theString+=""+msgtext+"</b></td></tr><tr><td height='"+td2height+"' align='center' class='td2style'><a href='javascript:Domsg(\"Yes\")' class='linkstyle'>Yes</a>&nbsp &nbsp<a href='javascript:Domsg(\"No\")' class='linkstyle'>No</a></td></tr></table>"
if (document.layers) // Netscape 4.0+
{
document.formbox.document.write(theString)
document.formbox.document.close()
document.formbox.left=msgleft
document.formbox.top=msgtop+40
document.formbox.visibility="show"
}
else
{
if(document.getElementById) // Internet Explorer 5.0+ and Netscape 6.0+
{
elm=document.getElementById("formbox")
elm.innerHTML=theString
elm.style.top=msgtop
elm.style.left=msgleft
elm.style.visibility = "visible"
}
}
}

// This function is for hiding the div
function hidebox()
{
if (document.layers) // Netscape 4.0+
{
document.formbox.visibility="hidden"
}
if(document.getElementById) // Netscape 6.0+ and Internet Explorer 5.0+
{
elm.style.visibility="hidden"
}
}
</script>
</head>
<body>
<div id="formbox" style="position:absolute;visibility:hidden;left:0;top:0;"></div>
<center>
<h1>Custom Confirm</h1>
<form name="formbx">
<input type="text" name="result" size="30">
</form>
<a href="javascript:DoFormbox('Are you sure?')">Click Me for a Confirm Box</a><br>
</center>
</body>
</html>

Spidey
11-04-2003, 01:10 PM
Hey thanks so much!

actually That's what I wnat to know, how can I modify that to use with the onSubmit part.....

I found something like that where the pop up box would call a function of the parent or the opener......and that function would ahve something like

function pickedChoice(blah) {

if (blah='yes')
{
do this
} else
{
do that
}

}

but the thing is, I want the form to continue to submit if the user clicked yes and stays the same if clicked no...so I would need to use a boolean function on onSUbmit.....and I don't really know how to convert something like that to use with the onSubmit....