RSS Forums RSS

javascript basic:

Please support our JavaScript / DHTML / AJAX advertiser: Programming Forums
Reply
Posts: 45
Reputation: complexcodes is an unknown quantity at this point 
Solved Threads: 1
complexcodes complexcodes is offline Offline
Light Poster

javascript basic:

  #1  
Nov 12th, 2008
My program should allow to display prompt box to enter values for a b and c and should display message in prompt box like "invalid number please enter number again" for a if a ==0 and a is not a number. Same with b , but b can be equal to 0 and has to be a number not any characters. and c can be equal to zero and has to be a number not any characters.
here is my code so far:
<script type="text/javascript">
  var aValue;
  aValue=window.prompt("What is a's value?","value goes here");
  while(aValue==0 ||(isNan(aValue)))
  {
     aValue=prompt("Invalid number, enter a value again:", " value here");
   }
   var bValue;
   bValue=window.prompt("what is b's value?","value goes here");
   while(!(isNan(bValue)))
   {
     bValue=prompt("Invalid number, enter again:","value here");
    }
   var cValue;
   cValue=prompt("what is c's value?","value goes here");
   while(!(isNan(cValue)))
   {
     cValue=prompt("Invalid number,enter again:","value goes here");   
   }
    </script>

How come it displays prompt box for a only? why am not I able to see prompt box for b and c?

Thanks,
AddThis Social Bookmark Button
Reply With Quote  
Posts: 728
Reputation: essential is on a distinguished road 
Solved Threads: 104
Featured Poster
Featured Coder
essential's Avatar
essential essential is offline Offline
Master Poster

Re: javascript basic:

  #2  
Nov 14th, 2008
Hope you'll enjoy my simple demo, on how to get around with prompt boxes. Good day...

  1. <html>
  2. <head>
  3. <title><!--Sample--></title>
  4. <script type="text/javascript">
  5. <!--
  6. function abc()
  7. { var validValue = /^[1-9]{1,4}$/;
  8. var openValue = /[0-9]/;
  9. var a = prompt('What is a\'s value?', 'Value goes here!');
  10.  
  11. do { if (!validValue.test(a)) {
  12. alert('You must enter a valid number value not lower than 1!');
  13. a = prompt('What is a\'s value?', 'Value goes here!'); }
  14.  
  15. }
  16. while(!validValue.test(a));
  17. var b = prompt('What is b\'s value?', 'Value goes here!');
  18.  
  19. do { if (!validValue.test(b)) {
  20. alert('You must enter a valid number value not lower than 1!');
  21. b = prompt('What is b\'s value?', 'Value goes here!'); }
  22. } while(!validValue.test(b));
  23. var c = prompt('What is c\'s value?', 'Value goes here!');
  24. do { if (!openValue.test(c)) {
  25. alert('Invalid character value, please enter another value!');
  26. c = prompt('What is c\'s value?', 'Value goes here!'); }
  27. } while(!openValue.test(c))
  28. var abcValue = ( a.valueOf() * 1) + (b.valueOf() * 1) + (c.valueOf() * 1);
  29. if ( document.all && !document.getElementById) {
  30. document.all.total.innerText = abcValue; }
  31. else if (document.getElementById) {
  32. document.getElementById('total').innerText = abcValue; }
  33. }
  34.  
  35. /* To make it available to all major browsers' */
  36. if (window.addEventListener)
  37. window.addEventListener('load',abc,false);
  38. else if (window.attachEvent)
  39. window.attachEvent('onload',abc)
  40. else if (document.getElementById)
  41. window.onload = abc;
  42. //-->
  43. </script>
  44. </head>
  45. <body>
  46. <!-- Just to catch the total value of a b and c! -->
  47. <div id="total"></div>
  48. </body>
  49. </html>
Last edited by essential : Nov 14th, 2008 at 9:18 am.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.



Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum
Views: 1029 | Replies: 1 | Currently Viewing: 1 (0 members and 1 guests)

 

Thread Tools Display Modes
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 10:25 pm.
Newsletter Archive - Sitemap - Privacy Statement - Acceptable Use Policy - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC