By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,132 Members | 1,417 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,132 IT Pros & Developers. It's quick & easy.

Value from Confirmation method in JavaScript

grkovski
P: 4
How I can retreive the value from the confirmation method in JavaScript?
Jan 21 '08 #1
Share this Question
Share on Google+
5 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

i guess you mean this:

Expand|Select|Wrap|Line Numbers
  1. var val = window.confirm('select ok or cancel');
the variable val gets true or false assigned depending on the users decision ...

kind regards
Jan 21 '08 #2

grkovski
P: 4
Hi, gits.
Thanks for fast replying.

I understand that, but:

1. I would like to know exactly, like in prompt method: when you choose the cancel button in prompt you receive actually NULL value.

2. How I can check the retreived value from the confirmation method, if I eventually get it?

Regards,
grkovski
Jan 21 '08 #3

grkovski
P: 4
Hi, gits, me again:

Here is a code and please, Can you explain me where I am wrong:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4.  
  5. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  6.  
  7. <head>
  8. <script type="text/javascript">
  9.  
  10. function Name() {
  11. var state1=("Thank You.<br />Mr. <b>")
  12. var state2=("</b><br/ ><br /> You are registered now.")
  13. var name=prompt("Please, put yor name in a space provided:","Unknown");
  14. var getVAL=window.confirm("Press OK or CANCEL?");
  15. // Cancel button of the "prompt" retreives a value NULL
  16.     if (name!=null && name!=""){
  17.                     getVAL;    
  18.                     if (getVAL==null){
  19.                         Name();
  20.                     }
  21.                     else {
  22.                         document.write(state1 + name + state2);
  23.         }
  24.         }
  25.         else if (name==""){
  26.             alert("Sorry,You leave empty box, Please put your name in the box!");
  27.                     if (name==""){
  28.                         Name();
  29.                     }
  30.                     else if (name!=null && name!=""){
  31.                         document.write(state1 + name + state2);
  32.                     }
  33.                     }
  34.         else {
  35.             alert("Sorry, Now you leave the registration process!");
  36.         }
  37.         }
  38.  
  39. </script>
  40. </head>
  41. <body>
  42.  
  43. <input type="button" onclick="Name()" value="Display a prompt box" />
  44.  
  45. </body>
  46. </html>
  47.  
  48.  

Regards,
grkovski
Jan 21 '08 #4

gits
Expert Mod 5K+
P: 5,333
with FF 2.0.0.11 and IE 6 i receive either true or false correctly don't know why you have a null-value ... but you may do the following:

Expand|Select|Wrap|Line Numbers
  1. if (window.confirm('select ok or cancel')) {
  2.     alert('you clicked ok');
  3. } else {
  4.     alert('you clicked cancel');
  5. }
  6.  
btw. should getVAL be a function? actually its a variable and gets immediatly assigned true or false when your code runs and after you got your prompt ... so your line 16 is useless ...

kind regards
Jan 21 '08 #5

grkovski
P: 4
Hi gits,

Finally, I found the exact code in my intention. I made mistake with a method:
Confirm method doesn't give a "null" value, only "true" and "false". I wrote code, tested and it's working perfect, it's OK, but it is still huge....

Thank you, gits
because you change my mind in the other way, right way, to think.

Here is:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3.     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5. <head>
  6. <script type="text/javascript">
  7.  
  8. function Name() {
  9. var state1=("Thank You.<br />Mr. <b>")
  10. var state2=("</b><br/ ><br /> You are registered now.")
  11. var name=prompt("Please, put yor name in a space provided:","Unknown");
  12. var getVAL=window.confirm("Press OK or CANCEL?");
  13. /* Cancel button of the "prompt" retreives a value NULL because
  14. has two values from the method itself and from the text box,
  15. so that's why Cancel is NULL because maybe textbox already has filled value
  16. from the user.*/
  17.     if (name!=null && name!=""){
  18. /*Method CONFIRM retreive only "true" or "false because has no extra values,
  19. it has values only from the method itself */
  20.         getVAL;    //confirm method
  21.                     if (getVAL==false){
  22.                         Name();
  23.                     }
  24.                     else {
  25.                         document.write(state1 + name + state2);
  26.                     }
  27.                 }
  28.     else if (name==""){
  29.         alert("Sorry,The box is empty, Please put your name in the box!");
  30.                     if (name==""){
  31.                         Name();
  32.                     }
  33.                     else if (name!=null && name!=""){
  34.                         document.write(state1 + name + state2);
  35.                     }
  36.                 }
  37.     else if (name==null && name!=""){
  38.         getVAL;    //confirm("Are you sure you want to do this?");
  39.                     if (getVAL==false){
  40.                         Name();
  41.                     }
  42.                     else {
  43.         alert("Sorry, Now you leave the registration process!");
  44.  
  45.                     }
  46.                 }
  47.     else {
  48.         alert("Sorry, Now you leave the registration process!");
  49.         }
  50.     }
  51. </script>
  52. </head>
  53. <body>
  54.  <br />
  55. <input type="button" onclick="Name()" value="Display a prompt box" />
  56.  
  57. </body>
  58. </html>
  59.  
  60.  


Regards,
grkovski
Jan 21 '08 #6

Post your reply

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