hi,
In javascript, if i need a confirm window (dialog box) with more than 2 default buttons (ok, and cancel)...which means maybe add in a "yes to all" button. How should i do this?
Well, here's an example of a customized window with buttons. I tried to make it so you can edit the parameters as easy as possible, including number of buttons, button text, and return value for each button. You'll be able to completely customize the alert window by editing the code in RED. Everything else can remain as is. This is IE and NS compatible. Go ahead and copy the page onto your server and run it as is so you can see how it works.
// THIS SETS THE ALERT WINDOW
// AS A GLOBAL VARIABLE
var myAlert
// THIS ADDS THE BUTTONS TO A
// TWO DIMENSIONAL ARRAY
// DO NOT EDIT
function button_Def(text,value) {
this.text = text
this.value = value
}
// THIS DEFINES THE BUTTONS YOU WANT
// IN THE POPUP WINDOW.
var buttonGroup = new Array(3) // # OF BUTTONS
buttonGroup[0] = new button_Def('O.K.',1)
buttonGroup[1] = new button_Def('Cancel',2)
buttonGroup[2] = new button_Def('Change',3)
// THIS DEFINES THE WINDOW PARAMETERS
// IN THE ALERT BOX
var alert_text = "Would you like to submit or would you like to change the entries ?"
var alert_title = "Confirmation"
var winheight = '100'
var winwidth = '250'
// THIS CREATES THE DYNAMIC ALERT BOX
// DOES NOT REQUIRE ANY EDITING
function checkForm(form_ref) {
myAlert = window.open('','alert','width='+winwidth+',height='+winheight+',top=100,left=100')
var wC = '<html><head><title>'+alert_title+'</title></head>'
wC += '<body bgcolor="#C0C0C0" onBlur="self.focus();">'
wC += '<table border="0" width="100%" cellpadding="0" cellspacing="0">'
wC += '<tr><td width="100%" align="center"><font face="Arial" size="2"><strong>'
wC += alert_text
wC += '</font></strong></td></tr>'
wC += '<tr><td width="100%" align="center" height="50">'
for (m = 0; m < buttonGroup.length; m++) {
wC += '<input type="button" '
wC += 'value="'+buttonGroup[m].text+'" '
wC += 'onClick="self.opener.procButton('+buttonGroup[m].value+');"> '
}
wC += '</td></tr>'
wC += '</body></html>'
myAlert.document.open()
myAlert.document.write(wC)
myAlert.document.close()
}
// THIS IS THE FUNCTION THAT PROCESSES
// THE BUTTON CLICKS. b_val IS SET TO
// WHATEVER YOU DEFINE AS THE VALUE
// OF THE BUTTON WHEN YOU SET THOSE
// UP ABOVE.
function procButton(b_val) {
myAlert.close()
if (b_val == 1) {
document.forms[0].submit()
}
if (b_val == 2) {
// DO NOTHING THIS IS THE
// CANCEL BUTTON
}
if (b_val == 3) {
document.forms[0].firstname.value = "Enter New First Name"
document.forms[0].lastname.value = "Enter New Last Name"
}
}
//-->
</script>
</head>
<body>
<form>
First Name: <input type="text" name="firstname"><br>
Last Name: <input type="text" name="lastname"><br>
<input type="button" value="Submit" onClick="checkForm();">
</form>
</body>
</html>
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.