Click to See Complete Forum and Search --> : check for the 'YES' button being clicked?
sanjuT
08-19-2004, 09:10 AM
Hi!
I have an alert box that pops up when the user submits a form.
it asks the user a question (if a certain field is NOT filled in).
If they click 'YES', i want the focus to go to that form element.
If they click 'NO', the form continues normally.
How do I check if the 'YES' as been clicked on?
THANKS!!!
sciguyryan
08-19-2004, 09:14 AM
Try something like this:
function Clicked(Clicked){
return Clicked;
}
var Button = document.getElementById("Your Buttons ID here");
Button.onclick = Clicked(true);
if (Clicked()){
window.alert("Button Clicked!");
}
Hope that helps,
RyanJ
sanjuT
08-19-2004, 09:19 AM
thanks, but i am unclear how to use that.
i have this:
if (((f.username1dir.value==null) || (f.username1dir.value=="")) && (!f.homedir1.checked))
{
alert("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nDid the user have computer access?");
}
I was thinking i could check for the YES being clicked here, with a return true or false type thing, then put in the focus() part after.
sciguyryan
08-19-2004, 09:25 AM
Originally posted by sanjuT
thanks, but i am unclear how to use that.
i have this:
if (((f.username1dir.value==null) || (f.username1dir.value=="")) && (!f.homedir1.checked))
{
alert("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nDid the user have computer access?");
}
I was thinking i could check for the YES being clicked here, with a return true or false type thing, then put in the focus() part after.
Sorry, I was thinking of an element button from a form.
From alert boxes you can never tell weather they click "ok" or "cancel".
RyanJ
sanjuT
08-19-2004, 09:28 AM
REALLY?? i thought a 'true' or 'false' is returned.
Oh well, do you know of another way to do what I am trying?
sciguyryan
08-19-2004, 09:31 AM
Originally posted by sanjuT
REALLY?? i thought a 'true' or 'false' is returned.
Oh well, do you know of another way to do what I am trying?
Yes, try this code:
if (((f.username1dir.value==null) || (f.username1dir.value=="")) && (!f.homedir1.checked)){
var Confirmed = window.confirm("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nDid the user have computer access?");
if (Confirmed){
// Put what you like here if they click OK
}
if (!Confirmed){
// Put what you like here if they click Cancel
}
}
Hope that helps,
RyanJ
Charles
08-19-2004, 09:35 AM
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Content-Script-Type" content="text/javascript">
<meta name="Content-Style-Type" content="text/css">
<title>Example</title>
</head>
<body>
<form action="someScript.pl" onsubmit="if (!/\S/.test(this.foo.value) && confirm(this.foo.previousSibling.data + '?')) {this.foo.focus(); return false}">
<fieldset>
<label>Foo <input id="foo" type="text"></label>
<button type="submit">Submit</button>
</fieldset>
</form>
</body>
</html>
sanjuT
08-19-2004, 10:15 AM
Originally posted by sciguyryan
[B]Yes, try this code:
if (((f.username1dir.value==null) || (f.username1dir.value=="")) && (!f.homedir1.checked)){
var Confirmed = window.confirm("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nDid the user have computer access?");
if (Confirmed){
// Put what you like here if they click OK
}
if (!Confirmed){
// Put what you like here if they click Cancel
}
}
THANKS, I am using this:
if (((f.username1dir.value==null) || (f.username1dir.value=="")) && (!f.homedir1.checked)) || (((f.username1gw.value==null) || (f.username1gw.value=="")) && (!f.gw1.checked))
{
var Confirmed = window.confirm("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nIf the user had computer access, click CANCEL to return to the form. If the user did NOT have computer access, click OK.");
if (Confirmed){
}
if (!Confirmed){
return false;
}
}
Charles
08-19-2004, 10:25 AM
You can shorten all of that to:
if ((!/\S/.test(f.username1dir.value) && !f.homedir1.checked) || (!/\S/.test(f.username1gw.value) && !f.gw1.checked) return window.confirm("If the terminated user had computer access, you must indicate what you would like to do with their Home Directory.\r\nIf the user had computer access, click CANCEL to return to the form. If the user did NOT have computer access, click OK.");
sanjuT
08-19-2004, 10:26 AM
Thanks, I have it working now (i think :) ) but i'll take a look at what u posted in a bit. kinda under a deadline right now.