473,385 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

How to create yes/no dialog in javascript?

Hi, how can I create a javascript popup that prompts users to press yes or no. I want something similar to Confirm(), but I want the message to say "yes/no" instead of "ok/cancel".

Also I know this is possible through vbscript, but I don't want to use vbscript since it is IE only.

Does anyone know a solution to this problem (I don't want to change the question in order to make it sense that the user enter "ok/cancel" )

Is there a way to create this kind of popup?
I need help please!
Jul 21 '07 #1
18 5031
gits
5,390 Expert Mod 4TB
hi ...

unfortunatly there is no way to set the text of the buttons in the js-confirm-dialog. but you may create one with html/css for yourself ...

kind regards
Jul 21 '07 #2
hi ...

unfortunatly there is no way to set the text of the buttons in the js-confirm-dialog. but you may create one with html/css for yourself ...

kind regards
Hi, thanks for your answer, Can you please give me a link or show me how to create one with html/css ?
Jul 21 '07 #3
gits
5,390 Expert Mod 4TB
heya ...

quickly wrote one ;) ... that should show the possibilities ... its not really ready or real cool yet but it works correct ... may be i'll work at it the next time ... for fun ;)) ...

[HTML]<html>
<head>
<script>
function CUST_CONFIRM(params) {
this.ok = typeof params.ok != 'undefined' ? params.ok
: 'Ok';
this.cancel = typeof params.cancel != 'undefined' ?
params.cancel : 'Cancel';
this.msg = typeof params.message != 'undefined' ?
params.message : '';

ok_cb = typeof params.ok_cb != 'undefined' ? params.ok_cb
: function() {};
cncl_cb = typeof params.cancel_cb != 'undefined' ?
params.cancel_cb : function() {};

this.ok_cb = function() {
var cp = document.getElementById('cust_confirm_popup');
document.lastChild.lastChild.removeChild(cp);

ok_cb();
};

this.cncl_cb = function() {
var cp = document.getElementById('cust_confirm_popup');
document.lastChild.lastChild.removeChild(cp);

cncl_cb();
};

this._build_dom();
}

CUST_CONFIRM.prototype._build_dom = function() {
var confirm_container = document.createElement('div');

confirm_container.id = 'cust_confirm_popup';
confirm_container.style['z-index'] = '1';
confirm_container.style.position = 'absolute';
confirm_container.style.left = '0px';
confirm_container.style.top = '50%';
confirm_container.style.width = '100%';

var container = document.createElement('div');

container.style['z-index'] = '2';
container.style.marginLeft = '-50px';
container.style.position = 'absolute';
container.style.border = '1px solid black';
container.style.color = 'red';
container.style.left = '50%';
container.style.top = '-10px';
container.style.padding = '5px 5px 5px 5px';

container.innerHTML = this.msg + '<br/><div></div>';

var ok_btn = document.createElement('input');

ok_btn.type = 'button';
ok_btn.value = this.ok;
ok_btn.onclick = this.ok_cb;

container.lastChild.appendChild(ok_btn);

var cncl_btn = document.createElement('input');

cncl_btn.type = 'button';
cncl_btn.value = this.cancel;
cncl_btn.onclick = this.cncl_cb;

container.lastChild.appendChild(cncl_btn);

confirm_container.appendChild(container);
document.lastChild.lastChild.appendChild(confirm_c ontainer);
}

function custom_confirm(params) {
var confirm = new CUST_CONFIRM(params);
}

function do_ok() {
alert('ok');
}

function do_cancel() {
alert('cancel');
}
</script>
</head>
<body>
<input type="button" value="open custom confirm"
onclick="
var params = {
ok: 'Yes',
cancel: 'No',
message: 'Are you sure?',
ok_cb: do_ok,
cancel_cb: do_cancel
};
custom_confirm(params);
"/>
</body>
</html>[/HTML]

kind regards
Jul 21 '07 #4
gits
5,390 Expert Mod 4TB
ahhh ... and now i'm proud to mention that it works in moz/ff/etc. and IE too ;)) ...

to make it real slick we should put the widget (the shown CUST_CONFIRM-class) into an external js-file. optimizing the dom-handling must follow (store node-refs, cleanup when no longer needed etc. is to be made )... at the end we should have a custom confirm widget ;)

kind regards
Jul 21 '07 #5
ahhh ... and now i'm proud to mention that it works in moz/ff/etc. and IE too ;)) ...

to make it real slick we should put the widget (the shown CUST_CONFIRM-class) into an external js-file. optimizing the dom-handling must follow (store node-refs, cleanup when no longer needed etc. is to be made )... at the end we should have a custom confirm widget ;)

kind regards

Hii,
Thank soooo Much for your help, I really appreciate it.

But I'm following the steps, first I saved the whole file as an html file and I received an error.. Then after you said that I should make the CUST_CONFIRM class as external js, can you please tell me what code should I extract exactly from the above html.

I'm really confused cause I see the answer and it's not working for me :(

Thanks in advance
Jul 21 '07 #6
gits
5,390 Expert Mod 4TB
Hii,
Thank soooo Much for your help, I really appreciate it.

But I'm following the steps, first I saved the whole file as an html file and I received an error.. Then after you said that I should make the CUST_CONFIRM class as external js, can you please tell me what code should I extract exactly from the above html.

I'm really confused cause I see the answer and it's not working for me :(

Thanks in advance
heya ...

it works as it is ... but you have to pay attention to line 74 in the above code. for whatever reason the code view here places spaces in ... so remove them at the end of the line where the confirm_container!! is appended ..

kind regards
Jul 22 '07 #7
heya ...

it works as it is ... but you have to pay attention to line 74 in the above code. for whatever reason the code view here places spaces in ... so remove them at the end of the line where the confirm_container!! is appended ..

kind regards

wowwwwwwwwwwwwww! amazinggggggggggggggggg

gits............THANKSSSSSSSSSSS SOOOO MUCH


YOU SAVE MY LIFE HEHEHE.

REGARDS
Jul 22 '07 #8
gits
5,390 Expert Mod 4TB
;) ... no problem ... glad to be able to help you ... in case you have more questions, come back to TSDN and post them ... anytime ;)

kind regards
Jul 22 '07 #9
;) ... no problem ... glad to be able to help you ... in case you have more questions, come back to TSDN and post them ... anytime ;)

kind regards
Hey gits, I was wondering if we can change the background color of the div tag so that it looks exactly like the "Confirm()" function, because I don't want the alert to look like it's inside the page, I dont want users to figure this out... Also how to stretch the buttons widths?

Regards
Jul 23 '07 #10
gits
5,390 Expert Mod 4TB
Hey gits, I was wondering if we can change the background color of the div tag so that it looks exactly like the "Confirm()" function, because I don't want the alert to look like it's inside the page, I dont want users to figure this out... Also how to stretch the buttons widths?

Regards
hi ...

have a look at the code ... especially at the lines where we set the style-properties. there you may 'play' with everything you want ... backgroundColor of the confirm_container, for the buttons you have to add the style-setting-lines ... its only css-stuff now ... what you are looking for ;)

kind regards
Jul 23 '07 #11
hi ...

have a look at the code ... especially at the lines where we set the style-properties. there you may 'play' with everything you want ... backgroundColor of the confirm_container, for the buttons you have to add the style-setting-lines ... its only css-stuff now ... what you are looking for ;)

kind regards
hehe I can't believe how fast you are. A week ago I registered in thescripts.com , before I used to search on google and find answers. So then I said, what if I couldn't find an answer to my questions (that was happening alot lately), so I registered in the site here and wondering if this will solve my problem.

And Frankly, I'm so happy and satisfied.

Thank you guys, you are amazing....

Best regards,
Wassim
Jul 23 '07 #12
gits
5,390 Expert Mod 4TB
... as i said ... come back anytime with more questions ... ;)
Jul 23 '07 #13
... as i said ... come back anytime with more questions ... ;)

gits, I posted a question like a week ago that was never answered, can you please check it out and tell me if you can help me?

it's a vb.net problem , check the link

http://www.thescripts.com/forum/thread679870-custom+button.html

Regards,
Wassim
Jul 23 '07 #14
gits
5,390 Expert Mod 4TB
gits, I posted a question like a week ago that was never answered, can you please check it out and tell me if you can help me?

it's a vb.net problem , check the link

http://www.thescripts.com/forum/thre...om+button.html

Regards,
Wassim
heya ...

you got an answer yesterday ... so let the thread go its way ... unfortunatly i can't really help you with this one ...

kind regards
Jul 23 '07 #15
heya ...

you got an answer yesterday ... so let the thread go its way ... unfortunatly i can't really help you with this one ...

kind regards
okay thanks
I appreciate your help anyway :)

regards,
Wassim
Jul 23 '07 #16
just a question, how do i put that script in an "<a href"? thanks in advance
Aug 5 '07 #17
Nojtb
4
im guessing best way with css html, well easist not best would make a page costumly made with yes & no buttons that do whatever they where suppost to as a alert.
and instead of a alert box popup make the new page created as a popup itself.

thats the cheap easy way out i would use atm :P
Aug 5 '07 #18
collie
2
Hi,

I am using .net 2.0. I tried to implement your code but it gives me the error:
unexpected call to method or property access
Do you know what could cause this error?

Many thanks
Aug 23 '07 #19

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Martin | last post by:
I have a situation where I'm displaying some information in a table on a web page. I've given the user the ability to make several different "queries" and show different sub-sets of the data. I...
3
by: Balaji M | last post by:
Is there any way to create a modal dialog in the html, which should work in both ie and netscape. the one window.showmodaldialog works well in ie, but not in netscape i found a way to keep the...
6
by: JCO | last post by:
Does anybody have a Download Dialog written in JavaScripts? This is for a website. I've seen it done before.... where you click on what you want and the dialog comes up asking you if you want to...
2
by: jm | last post by:
I have a parent window: <script language="javascript"> function doSearch() { result=showModalDialog("searchmni.aspx?lastname=smith"); alert(result); } </script>
4
by: Hitesh | last post by:
Hi, I am opening an Modal dialog box using the window.Showmodaldialogbox(), and in that window i am having an aspx form with say one ASP.NET Button control. i am doing some operation on the...
2
by: Jake Barnes | last post by:
Using javascript closures to create singletons to ensure the survival of a reference to an HTML block when removeChild() may remove the last reference to the block and thus destory the block is...
2
by: sthrudel | last post by:
Hi! I'm working on a web application in Asp.net and what I would like to have is a cross borwser modal dialog which accepts user's input. I would like to catch what the user clicked on the...
11
by: Bit Byte | last post by:
I am trying to create a multi-tabbed 'dialog' box (similar to the one displayed when Tools->Options is selected in most MS Office apps). Ofcourse, this is for a website, so I'm not sure if i can...
4
by: mamun | last post by:
Hi All, I have the following situation and am looking for answer in C#. I have a datagrid and putting checkbox next to each record. In the header I have a Delete button. I want users to...
1
by: mikeh3275 | last post by:
I'm new to developing in jQuery, so I'm probably doing this wrong. I'm loading a form into a modal dialog box and I'm trying to assign a click event to the button in the form, but I can't seem to...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.