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

prompt window value to alert window problem

P: 1
I need to know how can I exclude a data item from the Alert Window’s list message if the user leaves a prompt window blank.

Example :
If the user types a value to both “idnumber” and “department” prompt but leaves the “access” prompt empty or clicks cancel, I want the Alert Message List to look…

LIKE THIS:
ID Number: “value”
Department: “value”

and …

NOT LIKE THIS
ID Number:”value”
Access Code: null
Department: “value”

NOR LIKE THIS:
ID Number: “value”
Access Code: undefined
Department: “value”


Expand|Select|Wrap|Line Numbers
  1. <head>
  2. <script type="text/javascript">
  3.  
  4. function Information() {
  5.     idnumber = window.prompt("Type your ID Number", "");    
  6.     access = window.prompt("Type your Access Code", "");
  7.     department = window.prompt("Type your Department", "");
  8.  
  9. window.alert( "ID Number: " + idnumber + '\n' +"Access Code: " + access + '\n' +"Department: " + department + '\n' ); }    
  10. </script>
  11. </head>
  12.  
  13.  
  14.  
  15. <body>
  16. <script type="text/javascript">
  17.  
  18. information();
  19.  
  20. </script>
  21. </body>
  22. </html>
Apr 29 '10 #1
Share this Question
Share on Google+
1 Reply


gits
Expert Mod 5K+
P: 5,282
a simple if-statement like in the following example would do the job:

Expand|Select|Wrap|Line Numbers
  1. function Information() {
  2.     var idnumber = window.prompt("Type your ID Number", "");    
  3.     var access = window.prompt("Type your Access Code", "");
  4.     var department = window.prompt("Type your Department", "");
  5.  
  6.     var message = '';
  7.  
  8.     if ( idnumber != null ) {
  9.         message += 'ID number: ' + idnumber;
  10.     }
  11.  
  12.     window.alert( message );
  13. }
so if you cancel the idnumber-prompt then the alert should be empty.

kind regards
Apr 29 '10 #2

Post your reply

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